Skip to content

Commit ba3c51f

Browse files
committed
Fix service-entry spans inheriting gateway domain name as service name under inferred proxy spans
When an inferred proxy span is the parent, the service-entry span was inheriting its service name (the gateway domain name, e.g. system-tests-api-gateway.com) instead of using the application's configured service name. Reset the service name to the configured DD_SERVICE value in HttpServerDecorator.startSpan() when an inferred proxy parent is detected.
1 parent 244c586 commit ba3c51f

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public Context startSpan(REQUEST_CARRIER carrier, Context parentContext) {
178178
// finish calls from child spans (e.g., Spring MVC handler) are deferred until the
179179
// service-entry span finishes (after the response status is known).
180180
registerServiceEntrySpanInInferredProxy(parentContext, span);
181+
// Reset service name inherited from inferred proxy parent: the inferred span uses the
182+
// gateway domain name as service name, but the service-entry span should identify
183+
// the application (configured DD_SERVICE), not the upstream gateway.
184+
resetServiceNameIfUnderInferredProxy(parentContext, span);
181185
// Apply RequestBlockingAction if any
182186
Flow<Void> flow = callIGCallbackRequestHeaders(span, carrier);
183187
if (flow.getAction() instanceof RequestBlockingAction) {
@@ -205,6 +209,12 @@ private void registerServiceEntrySpanInInferredProxy(
205209
}
206210
}
207211

212+
private void resetServiceNameIfUnderInferredProxy(Context parentContext, AgentSpan span) {
213+
if (InferredProxySpan.fromContext(parentContext) != null) {
214+
span.setServiceName(Config.get().getServiceName());
215+
}
216+
}
217+
208218
private final DataStreamsTransactionTracker.TransactionSourceReader
209219
DSM_TRANSACTION_SOURCE_READER =
210220
(source, headerName) -> {

dd-java-agent/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/src/test/groovy/test/boot/SpringBootBasedTest.groovy

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,8 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
543543
}
544544
}
545545
// Server span should be a child of the inferred proxy span
546-
// When there's an inferred proxy span parent, the server span inherits the parent's service name
547546
span {
548-
// Service name is inherited from the inferred proxy span parent
549-
serviceName "api.example.com"
547+
serviceName expectedServiceName()
550548
operationName operation()
551549
resourceName expectedResourceName(SUCCESS, "GET", address)
552550
spanType DDSpanTypes.HTTP_SERVER
@@ -570,9 +568,8 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
570568
}
571569
}
572570
if (hasHandlerSpan()) {
573-
// Handler span inherits service name from inferred proxy span parent
574571
it.span {
575-
serviceName "api.example.com"
572+
serviceName expectedServiceName()
576573
operationName "spring.handler"
577574
resourceName "TestController.success"
578575
spanType DDSpanTypes.HTTP_SERVER
@@ -585,9 +582,8 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
585582
}
586583
}
587584
}
588-
// Controller span also inherits service name
589585
it.span {
590-
serviceName "api.example.com"
586+
serviceName expectedServiceName()
591587
operationName "controller"
592588
resourceName "controller"
593589
errored false

0 commit comments

Comments
 (0)