Last active
September 20, 2018 16:26
-
-
Save itsderek23/e66cee2ed6abfbcd2e5797003c838cea to your computer and use it in GitHub Desktop.
Breakout HTTP calls to specified domains in Scout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This modification provides more fine-grained visiblity of HTTP calls within Scout, breaking out time spent in HTTP calls for specified domains. | |
# | |
# Instructions: | |
# 1. `bundle update scout_apm`. Older versions of `scout_apm` have a bug w/disabling instrumentation. | |
# | |
# 2. Disable Scout's default HTTP instrumentation: | |
# config/scout_apm.yml | |
# production: | |
# <<: *defaults | |
# disabled_instruments: ['NetHttp'] | |
# | |
# 3. Specify domains to display in Scout's overview charts in +SCOUT_HTTP_DOMAINS+. Those that don't appear will be aggregrated under "HTTP", | |
# which is the default behavior of the NetHttp instrument. | |
# If the domain is included in +SCOUT_HTTP_DOMAINS+, it will be listed seperately in Scout's timeseries charts. | |
# A reasonable breakout limit is ~5 unique domains. | |
SCOUT_HTTP_DOMAINS = ['api.statuspage.io', 'github.com', 'api.authy.com'] | |
if !ScoutApm::Agent.instance.instrument_manager.installed_instruments.any? { |instance| instance.is_a?(ScoutApm::Instruments::NetHttp) } | |
ScoutApm::Agent.instance.logger.info "Installing NetHttpWithDomain instrument." | |
::Net::HTTP.class_eval do | |
include ScoutApm::Tracer | |
def request_with_scout_instruments(*args,&block) | |
self.class.instrument(scout_bucket(@address), "request", :ignore_children => true, :desc => request_scout_description(args.first)) do | |
request_without_scout_instruments(*args, &block) | |
end | |
end | |
def scout_bucket(address) | |
SCOUT_HTTP_DOMAINS.any? { |domain| address == domain } ? address : 'HTTP' | |
end | |
def request_scout_description(req) | |
path = req.path | |
path = path.path if path.respond_to?(:path) | |
max_length = ScoutApm::Agent.instance.context.config.value('instrument_http_url_length') | |
(@address + path.split('?').first)[0..(max_length - 1)] | |
end | |
alias request_without_scout_instruments request | |
alias request request_with_scout_instruments | |
end | |
else | |
ScoutApm::Agent.instance.logger.info "NOT installing NetHttpWithDomain instrument. NetHttp instrument isn't disabled." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment