@@ -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
0 commit comments