Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public static AgentScope activateNext(final AgentSpan span) {
}

public static TraceConfig traceConfig(final AgentSpan span) {
return null != span ? span.traceConfig() : traceConfig();
final TraceConfig config = span == null ? null : span.traceConfig();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

span.traceConfig returns null for ExtractedSpan.
Arguably, we'd be better fixing ExtracedSpan, but I'm curious what others think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO fixing ExtractedSpan to return AgentTracer.traceConfig() would be better.

return config == null ? traceConfig() : config;
}

public static TraceConfig traceConfig() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package datadog.trace.bootstrap.instrumentation.api;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import datadog.trace.api.TraceConfig;
import org.junit.jupiter.api.Test;

class AgentTracerTest {

@Test
void traceConfigOfNullSpanFallsBackToGlobalConfig() {
assertSame(AgentTracer.traceConfig(), AgentTracer.traceConfig((AgentSpan) null));
}

@Test
void traceConfigOfSpanWithOwnConfigReturnsThatConfig() {
TraceConfig ownConfig = mock(TraceConfig.class);
AgentSpan span = mock(AgentSpan.class);
when(span.traceConfig()).thenReturn(ownConfig);

assertSame(ownConfig, AgentTracer.traceConfig(span));
}

// Regression test: a span wrapping only an extracted remote context (e.g. built via
// AgentSpan.fromSpanContext for a propagated-but-not-yet-local trace) reports a null
// TraceConfig. Callers such as LogbackLoggerInstrumentation$CallAppendersAdvice do
// `traceConfig(span).isLogsInjectionEnabled()` without a further null check, so
// traceConfig(AgentSpan) must never return null for a non-null span.
@Test
void traceConfigOfExtractedSpanFallsBackToGlobalConfigInsteadOfNull() {
AgentSpan extractedSpan = AgentSpan.fromSpanContext(new TagContext());

assertNull(
extractedSpan.traceConfig(),
"test setup: expected the extracted span itself to report a null config");

TraceConfig config = AgentTracer.traceConfig(extractedSpan);

assertNotNull(config);
assertSame(AgentTracer.traceConfig(), config);
}
}
Loading