Skip to content

Commit

Permalink
do not create a new emitter when a shared emitter is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
hden committed Nov 16, 2021
1 parent 7e93511 commit 0260158
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public class AWSXRayRecorder {
private boolean forcedTraceIdGeneration;

public AWSXRayRecorder() {
this(null);
}

AWSXRayRecorder(Emitter sharedEmitter) {
samplingStrategy = new DefaultSamplingStrategy();
streamingStrategy = new DefaultStreamingStrategy();
prioritizationStrategy = new DefaultPrioritizationStrategy();
Expand Down Expand Up @@ -175,10 +179,14 @@ public AWSXRayRecorder() {
serviceRuntimeContext = new ConcurrentHashMap<>();
serviceRuntimeContext.putAll(RUNTIME_INFORMATION);

try {
emitter = Emitter.create();
} catch (IOException e) {
throw new RuntimeException("Unable to instantiate AWSXRayRecorder: ", e);
if (sharedEmitter != null) {
emitter = sharedEmitter;
} else {
try {
emitter = Emitter.create();
} catch (IOException e) {
throw new RuntimeException("Unable to instantiate AWSXRayRecorder: ", e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public AWSXRayRecorderBuilder withForcedTraceIdGeneration() {
* @return a configured instance of AWSXRayRecorder
*/
public AWSXRayRecorder build() {
AWSXRayRecorder client = new AWSXRayRecorder();
AWSXRayRecorder client = new AWSXRayRecorder(emitter);

if (samplingStrategy != null) {
client.setSamplingStrategy(samplingStrategy);
Expand All @@ -291,10 +291,6 @@ public AWSXRayRecorder build() {
client.setSegmentContextResolverChain(segmentContextResolverChain);
}

if (emitter != null) {
client.setEmitter(emitter);
}

if (!segmentListeners.isEmpty()) {
client.addAllSegmentListeners(segmentListeners);
}
Expand Down

0 comments on commit 0260158

Please sign in to comment.