fix(core): prevents CentralizedSamplingStrategy from instatiating extraneous recorders when no origin set #59
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.
Issue #, if available:
#46
Description of changes:
Problem
Currently, when the
CentralizedSamplingStrategy
is used, the shouldTrace method checks if the providedsamplingRequest
has a service type provided. If it does not, a defaultAWSXRayRecorder
will be instantiated, and its origin retrieved. This leads to a new recorder being instantiated for every invocation as a worst case.Background
The
origin
that gets passed as theserviceType
to theSamplingRequest
can either be explicitly set on an AWSXRayRecorder, or set by a plugin that is provided to the recorder.In the current implementation, the user does not have access to the newly created recorder, and so can not explicitly set the
origin
or add any plugins. The default recorder also does not contain any plugins. This means that we can be sure the origin is never present on the instantiated recorder.Solution
This change removes the
getServiceType()
check, and stops attempting to set the service type on thesamplingRequest
. This has no change on behavior apart from reducing the number of recorders instantiated.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.