Suppress segments in HttpUrlConnection #2365
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #2337
Our HttpUrlConnection instrumentation creates a tracer for each response handler called by the HttpUrlConnection instance. We do this to ensure we have some tracer available to report the external call. This isn't ideal, because only the first tracer gets used to report the external, but it is not known at the time each tracer is created (via
@Trace
annotation) whether it is the first one. The result is that HttpUrlConnection transaction traces/DTs may be cluttered with a great number of response handler segments (such asgetInputStream
) that weren't chosen to become externals.This PR introduces a low-verbose mode to give users the option of suppressing these non-external segments in transaction traces and DTs. This can be enabled by setting:
NEW_RELIC_CLASS_TRANSFORMER_COM_NEWRELIC_INSTRUMENTATION_HTTURLCONNECTION_VERBOSE=false
, sys prop-Dnewrelic.config.class_transformer.com.newrelic.instrumentation.httpurlconnection.verbose=false
, or equivalent stanza innewrelic.yml
. Default setting istrue
(ie, non-externalgetInputStream
and other response handler methods will be reported as before).Implementation comments
This functionality is implemented via an internal-only API method,
excludeLeaf
, which has the ability to toggle theexcludes
tracer flag on leaf tracers, just like the annotation@Trace(excludeFromTransactionTrace=true)
. The difference is that the newexcludeLeaf
method can be called after the tracer has already been created, whereas the annotation applies only when the tracer is constructed.excludeLeaf
is a no-op everywhere but inDefaultTracer
. It is also a no-op in root tracer implementations to stay consistent with our existing agent behavior that prohibits root tracers from being excluded.We chose to make
excludeLeaf
(rather than a generalexcludeTracer
) to ensure we don't unintentionally exclude parent tracers and orphan their children. However, this could be revisited in the future as a potential enhancement.Tests
There are a few new unit tests, plus a small AIT update for the HttpUrlConnection instrumentation. AIT branch is here and test run for that against this PR is here.