Skip to content

Commit 8305d62

Browse files
committed
review feedback
1 parent 591efc8 commit 8305d62

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/context/OtelContext.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class OtelContext implements Context {
2121
private static final String OTEL_CONTEXT_SPAN_KEY = "opentelemetry-trace-span-key";
2222
private static final String OTEL_CONTEXT_ROOT_SPAN_KEY = "opentelemetry-traces-local-root-span";
2323

24-
private static final Map<ContextKey<?>, datadog.context.ContextKey<?>> CONTEXT_KEYS =
24+
/** Records the keys needed to access the delegate context, mapped by key name. */
25+
private static final Map<ContextKey<?>, datadog.context.ContextKey<?>> DELEGATE_KEYS =
2526
new ConcurrentHashMap<>();
2627

2728
private final datadog.context.Context delegate;
@@ -47,14 +48,15 @@ public <V> V get(ContextKey<V> key) {
4748
if (span != null) {
4849
return (V) toOtelSpan(span);
4950
}
50-
}
51-
if (OTEL_CONTEXT_ROOT_SPAN_KEY.equals(key.toString())) {
51+
// fall-through and check for non-datadog span data
52+
} else if (OTEL_CONTEXT_ROOT_SPAN_KEY.equals(key.toString())) {
5253
AgentSpan span = AgentSpan.fromContext(delegate);
5354
if (span != null) {
5455
return (V) toOtelSpan(span.getLocalRootSpan());
5556
}
57+
// fall-through and check for non-datadog span data
5658
}
57-
return (V) delegate.get(datadogKey(key));
59+
return (V) delegate.get(delegateKey(key));
5860
}
5961

6062
@Override
@@ -64,8 +66,9 @@ public <V> Context with(ContextKey<V> key, V value) {
6466
AgentSpan span = ((OtelSpan) value).asAgentSpan();
6567
return new OtelContext(delegate.with(span));
6668
}
69+
// fall-through and store as non-datadog span data
6770
}
68-
return new OtelContext(delegate.with(datadogKey(key), value));
71+
return new OtelContext(delegate.with(delegateKey(key), value));
6972
}
7073

7174
@Override
@@ -86,11 +89,11 @@ public String toString() {
8689
return "OtelContext{" + "delegate=" + delegate + '}';
8790
}
8891

89-
static datadog.context.ContextKey datadogKey(ContextKey key) {
90-
return CONTEXT_KEYS.computeIfAbsent(key, OtelContext::mapKeyByName);
92+
private static datadog.context.ContextKey delegateKey(ContextKey key) {
93+
return DELEGATE_KEYS.computeIfAbsent(key, OtelContext::mapByKeyName);
9194
}
9295

93-
private static datadog.context.ContextKey mapKeyByName(ContextKey key) {
96+
private static datadog.context.ContextKey mapByKeyName(ContextKey key) {
9497
return datadog.context.ContextKey.named(key.toString());
9598
}
9699

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/trace/OtelSpanBuilder.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ public Span startSpan() {
201201
setSpanKind(INTERNAL);
202202
}
203203
if (!this.ignoreActiveSpan) {
204-
Context context = Context.current();
205-
if (null != context) {
206-
setParent(context);
207-
}
204+
setParent(Context.current());
208205
}
209206
AgentSpan delegate = this.delegate.start();
210207
// Apply overrides

0 commit comments

Comments
 (0)