Skip to content

Commit 0260158

Browse files
committed
do not create a new emitter when a shared emitter is provided
1 parent 7e93511 commit 0260158

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorder.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public class AWSXRayRecorder {
138138
private boolean forcedTraceIdGeneration;
139139

140140
public AWSXRayRecorder() {
141+
this(null);
142+
}
143+
144+
AWSXRayRecorder(Emitter sharedEmitter) {
141145
samplingStrategy = new DefaultSamplingStrategy();
142146
streamingStrategy = new DefaultStreamingStrategy();
143147
prioritizationStrategy = new DefaultPrioritizationStrategy();
@@ -175,10 +179,14 @@ public AWSXRayRecorder() {
175179
serviceRuntimeContext = new ConcurrentHashMap<>();
176180
serviceRuntimeContext.putAll(RUNTIME_INFORMATION);
177181

178-
try {
179-
emitter = Emitter.create();
180-
} catch (IOException e) {
181-
throw new RuntimeException("Unable to instantiate AWSXRayRecorder: ", e);
182+
if (sharedEmitter != null) {
183+
emitter = sharedEmitter;
184+
} else {
185+
try {
186+
emitter = Emitter.create();
187+
} catch (IOException e) {
188+
throw new RuntimeException("Unable to instantiate AWSXRayRecorder: ", e);
189+
}
182190
}
183191
}
184192

aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorderBuilder.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public AWSXRayRecorderBuilder withForcedTraceIdGeneration() {
267267
* @return a configured instance of AWSXRayRecorder
268268
*/
269269
public AWSXRayRecorder build() {
270-
AWSXRayRecorder client = new AWSXRayRecorder();
270+
AWSXRayRecorder client = new AWSXRayRecorder(emitter);
271271

272272
if (samplingStrategy != null) {
273273
client.setSamplingStrategy(samplingStrategy);
@@ -291,10 +291,6 @@ public AWSXRayRecorder build() {
291291
client.setSegmentContextResolverChain(segmentContextResolverChain);
292292
}
293293

294-
if (emitter != null) {
295-
client.setEmitter(emitter);
296-
}
297-
298294
if (!segmentListeners.isEmpty()) {
299295
client.addAllSegmentListeners(segmentListeners);
300296
}

0 commit comments

Comments
 (0)