Skip to content

Commit fe50a9a

Browse files
Provide instrumentation name context to span (DataDog#5492)
1 parent 0dfea8a commit fe50a9a

38 files changed

Lines changed: 216 additions & 96 deletions

File tree

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpServerDecorator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,18 @@ public AgentSpan.Context.Extracted extract(REQUEST_CARRIER carrier) {
124124
return tracer().propagate().extract(carrier, getter);
125125
}
126126

127+
/** Deprecated. Use {@link #startSpan(String, Object, AgentSpan.Context.Extracted)} instead. */
128+
@Deprecated
127129
public AgentSpan startSpan(REQUEST_CARRIER carrier, AgentSpan.Context.Extracted context) {
128-
AgentSpan span = tracer().startSpan(spanName(), callIGCallbackStart(context)).setMeasured(true);
130+
return startSpan("http-server", carrier, context);
131+
}
132+
133+
public AgentSpan startSpan(
134+
String instrumentationName, REQUEST_CARRIER carrier, AgentSpan.Context.Extracted context) {
135+
AgentSpan span =
136+
tracer()
137+
.startSpan(instrumentationName, spanName(), callIGCallbackStart(context))
138+
.setMeasured(true);
129139
Flow<Void> flow = callIGCallbackRequestHeaders(span, carrier);
130140
if (flow.getAction() instanceof Flow.Action.RequestBlockingAction) {
131141
span.setRequestBlockingAction((Flow.Action.RequestBlockingAction) flow.getAction());

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/decorator/HttpServerDecoratorTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,14 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
421421
getRequestContext() >> reqCtxt
422422
}
423423
def mTracer = Mock(TracerAPI) {
424-
startSpan(_, _) >> mSpan
424+
startSpan(_, _, _) >> mSpan
425425
getCallbackProvider(RequestContextSlot.APPSEC) >> cbpAppSec
426426
getCallbackProvider(RequestContextSlot.IAST) >> CallbackProvider.CallbackProviderNoop.INSTANCE
427427
}
428428
def decorator = newDecorator(mTracer)
429429

430430
when:
431-
decorator.startSpan(headers, null)
431+
decorator.startSpan("test", headers, null)
432432

433433
then:
434434
1 * mSpan.setMeasured(true) >> mSpan

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/decorator/http/HttpResourceDecoratorTest.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HttpResourceDecoratorTest extends DDSpecification {
2626

2727
def "test that resource name is not changed"() {
2828
given:
29-
AgentSpan span = tracer.startSpan("test")
29+
AgentSpan span = tracer.startSpan("test", "test")
3030

3131
when:
3232
def scope = AgentTracer.activateSpan(span)
@@ -40,7 +40,7 @@ class HttpResourceDecoratorTest extends DDSpecification {
4040

4141
def "still uses the simple normalizer by default"() {
4242
given:
43-
AgentSpan span = tracer.startSpan("test")
43+
AgentSpan span = tracer.startSpan("test", "test")
4444
String method = "GET"
4545
String path = "/asdf/1234"
4646

@@ -55,7 +55,7 @@ class HttpResourceDecoratorTest extends DDSpecification {
5555
setup:
5656
injectSysConfig(TRACE_HTTP_SERVER_PATH_RESOURCE_NAME_MAPPING, "/asdf/*:/test")
5757

58-
AgentSpan span = tracer.startSpan("test")
58+
AgentSpan span = tracer.startSpan("test", "test")
5959
String method = "GET"
6060
String path = "/asdf/1234"
6161

@@ -70,7 +70,7 @@ class HttpResourceDecoratorTest extends DDSpecification {
7070
setup:
7171
injectSysConfig(TRACE_HTTP_SERVER_PATH_RESOURCE_NAME_MAPPING, "/asdf/*:/test")
7272

73-
AgentSpan span = tracer.startSpan("test")
73+
AgentSpan span = tracer.startSpan("test", "test")
7474
String method = "GET"
7575
String path = "/unknown/1234"
7676

@@ -86,7 +86,7 @@ class HttpResourceDecoratorTest extends DDSpecification {
8686
injectSysConfig(TRACE_HTTP_SERVER_PATH_RESOURCE_NAME_MAPPING, "/a/*:/test")
8787
injectSysConfig("trace.URLAsResourceNameRule.enabled", "false")
8888

89-
AgentSpan span = tracer.startSpan("test")
89+
AgentSpan span = tracer.startSpan("test", "test")
9090
String method = "GET"
9191
String path = "/unknown/1234"
9292

@@ -101,7 +101,7 @@ class HttpResourceDecoratorTest extends DDSpecification {
101101
setup:
102102
injectSysConfig(TRACE_HTTP_CLIENT_PATH_RESOURCE_NAME_MAPPING, "/a/*:/test")
103103

104-
AgentSpan span = tracer.startSpan("test")
104+
AgentSpan span = tracer.startSpan("test", "test")
105105

106106
when:
107107
decorator().withClientPath(span, "GET", "/a/foo")
@@ -114,7 +114,7 @@ class HttpResourceDecoratorTest extends DDSpecification {
114114
setup:
115115
injectSysConfig(TRACE_HTTP_CLIENT_PATH_RESOURCE_NAME_MAPPING, "/a/*:*")
116116

117-
AgentSpan span = tracer.startSpan("test")
117+
AgentSpan span = tracer.startSpan("test", "test")
118118

119119
when:
120120
decorator().withClientPath(span, "GET", "/a/foo")

dd-java-agent/agent-iast/src/main/java/com/datadog/iast/Reporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private AgentSpan startNewSpan() {
8484
new TagContext().withRequestContextDataIast(new IastRequestContext());
8585
final AgentSpan span =
8686
tracer()
87-
.startSpan(VULNERABILITY_SPAN_NAME, tagContext)
87+
.startSpan("iast", VULNERABILITY_SPAN_NAME, tagContext)
8888
.setSpanType(InternalSpanTypes.VULNERABILITY);
8989
ANALYZED.setTag(span);
9090
return span;

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/ReporterTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class ReporterTest extends DDSpecification {
166166

167167
then:
168168
noExceptionThrown()
169-
1 * tracerAPI.startSpan('vulnerability', _ as AgentSpan.Context) >> span
169+
1 * tracerAPI.startSpan('iast', 'vulnerability', _ as AgentSpan.Context) >> span
170170
1 * tracerAPI.activateSpan(span, ScopeSource.MANUAL) >> scope
171171
1 * span.getSpanId() >> spanId
172172
1 * span.getRequestContext() >> reqCtx

dd-java-agent/agent-iast/src/testFixtures/groovy/com/datadog/iast/test/IastAgentTestRunner.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class IastAgentTestRunner extends AgentTestRunner implements IastRequestContextP
5050

5151
def iastCtx = reqStartCb.get().result
5252
def ddctx = new TagContext().withRequestContextDataIast(iastCtx)
53-
AgentSpan span = TEST_TRACER.startSpan("test-iast-span", ddctx)
53+
AgentSpan span = TEST_TRACER.startSpan("test", "test-iast-span", ddctx)
5454
try {
5555
AgentTracer.activateSpan(span).withCloseable cl
5656
} finally {

dd-java-agent/instrumentation/java-lang/src/main/java/datadog/trace/instrumentation/java/lang/ProcessImplStartAdvice.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static AgentSpan startSpan(@Advice.Argument(0) final String[] command) th
2323

2424
Map<String, String> tags = ProcessImplInstrumentationHelpers.createTags(command);
2525
TagContext tagContext = new TagContext("appsec", tags);
26-
AgentSpan span = tracer.startSpan("command_execution", tagContext);
26+
AgentSpan span = tracer.startSpan("appsec", "command_execution", tagContext);
2727
span.setSpanType("system");
2828
span.setResourceName(ProcessImplInstrumentationHelpers.determineResource(command));
2929
return span;

dd-java-agent/instrumentation/opentelemetry/opentelemetry-0.3/src/main/java/datadog/trace/instrumentation/opentelemetry/OtelTracer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.concurrent.TimeUnit;
1616

1717
public class OtelTracer implements Tracer {
18+
private static final String INSTRUMENTATION_NAME = "otel";
1819
private final String tracerName;
1920
private final AgentTracer.TracerAPI tracer;
2021
private final TypeConverter converter;
@@ -52,7 +53,7 @@ private class SpanBuilder implements Span.Builder {
5253
private boolean parentSet = false;
5354

5455
public SpanBuilder(final String spanName) {
55-
delegate = tracer.buildSpan(tracerName).withResourceName(spanName);
56+
delegate = tracer.buildSpan(INSTRUMENTATION_NAME, tracerName).withResourceName(spanName);
5657
}
5758

5859
@Override

dd-java-agent/instrumentation/opentelemetry/opentelemetry-0.3/src/test/groovy/TypeConverterTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TypeConverterTest extends AgentTestRunner {
2323

2424
def "should avoid extra allocation for a span wrapper"() {
2525
def context = createTestSpanContext()
26-
def span1 = new DDSpan(0, context)
27-
def span2 = new DDSpan(0, context)
26+
def span1 = new DDSpan("test", 0, context)
27+
def span2 = new DDSpan("test", 0, context)
2828
expect:
2929
// return the same wrapper for the same span
3030
typeConverter.toSpan(span1) is typeConverter.toSpan(span1)
@@ -47,8 +47,8 @@ class TypeConverterTest extends AgentTestRunner {
4747
def "should avoid extra allocation for a scope wrapper"() {
4848
def scopeManager = new ContinuableScopeManager(0, false, true)
4949
def context = createTestSpanContext()
50-
def span1 = new DDSpan(0, context)
51-
def span2 = new DDSpan(0, context)
50+
def span1 = new DDSpan("test", 0, context)
51+
def span2 = new DDSpan("test", 0, context)
5252
def scope1 = scopeManager.activate(span1, ScopeSource.MANUAL)
5353
def scope2 = scopeManager.activate(span2, ScopeSource.MANUAL)
5454
expect:

dd-java-agent/instrumentation/opentelemetry/opentelemetry-1.4/src/main/java/datadog/trace/instrumentation/opentelemetry14/OtelTracer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
@ParametersAreNonnullByDefault
99
class OtelTracer implements Tracer {
10+
private static final String INSTRUMENTATION_NAME = "otel";
1011
private final AgentTracer.TracerAPI tracer;
1112
private final String instrumentationScopeName;
1213

@@ -17,7 +18,8 @@ public OtelTracer(String instrumentationScopeName) {
1718

1819
@Override
1920
public SpanBuilder spanBuilder(String spanName) {
20-
AgentTracer.SpanBuilder delegate = this.tracer.buildSpan(spanName).withResourceName(spanName);
21+
AgentTracer.SpanBuilder delegate =
22+
this.tracer.buildSpan(INSTRUMENTATION_NAME, spanName).withResourceName(spanName);
2123
return new OtelSpanBuilder(delegate);
2224
}
2325
}

0 commit comments

Comments
 (0)