@@ -21,7 +21,8 @@ public class OtelContext implements Context {
21
21
private static final String OTEL_CONTEXT_SPAN_KEY = "opentelemetry-trace-span-key" ;
22
22
private static final String OTEL_CONTEXT_ROOT_SPAN_KEY = "opentelemetry-traces-local-root-span" ;
23
23
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 =
25
26
new ConcurrentHashMap <>();
26
27
27
28
private final datadog .context .Context delegate ;
@@ -47,14 +48,15 @@ public <V> V get(ContextKey<V> key) {
47
48
if (span != null ) {
48
49
return (V ) toOtelSpan (span );
49
50
}
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 ())) {
52
53
AgentSpan span = AgentSpan .fromContext (delegate );
53
54
if (span != null ) {
54
55
return (V ) toOtelSpan (span .getLocalRootSpan ());
55
56
}
57
+ // fall-through and check for non-datadog span data
56
58
}
57
- return (V ) delegate .get (datadogKey (key ));
59
+ return (V ) delegate .get (delegateKey (key ));
58
60
}
59
61
60
62
@ Override
@@ -64,8 +66,9 @@ public <V> Context with(ContextKey<V> key, V value) {
64
66
AgentSpan span = ((OtelSpan ) value ).asAgentSpan ();
65
67
return new OtelContext (delegate .with (span ));
66
68
}
69
+ // fall-through and store as non-datadog span data
67
70
}
68
- return new OtelContext (delegate .with (datadogKey (key ), value ));
71
+ return new OtelContext (delegate .with (delegateKey (key ), value ));
69
72
}
70
73
71
74
@ Override
@@ -86,11 +89,11 @@ public String toString() {
86
89
return "OtelContext{" + "delegate=" + delegate + '}' ;
87
90
}
88
91
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 );
91
94
}
92
95
93
- private static datadog .context .ContextKey mapKeyByName (ContextKey key ) {
96
+ private static datadog .context .ContextKey mapByKeyName (ContextKey key ) {
94
97
return datadog .context .ContextKey .named (key .toString ());
95
98
}
96
99
0 commit comments