Skip to content

Commit 20abae4

Browse files
amarzialidevflow.devflow-routing-intake
andauthored
Track service name source (#10607)
wip Fix tests and finalise implementation Add ability to add extra tags for controller spans Enforce usage of new signature codenarc Fix tests Add base tests Use the real integration name for the preferred service name source muzzle Fix leftover rename Merge branch 'master' into andrea.marziali/serviename-integration Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 4789e89 commit 20abae4

File tree

75 files changed

+456
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+456
-137
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ protected String spanKind() {
1313

1414
@Override
1515
public AgentSpan afterStart(final AgentSpan span) {
16-
if (service() != null) {
17-
span.setServiceName(service());
16+
final String service = service();
17+
if (service != null) {
18+
span.setServiceName(service, component());
1819
}
1920
span.setTag(Tags.SPAN_KIND, spanKind());
2021

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public AgentSpan onConnection(final AgentSpan span, final CONNECTION connection)
7676
span.setTag(Tags.PEER_HOSTNAME, hostName);
7777

7878
if (Config.get().isDbClientSplitByHost()) {
79-
span.setServiceName(hostName.toString());
79+
span.setServiceName(hostName.toString(), component());
8080
}
8181
}
8282
}
@@ -88,7 +88,7 @@ protected AgentSpan onInstance(final AgentSpan span, final String dbInstance) {
8888
span.setTag(Tags.DB_INSTANCE, dbInstance);
8989
String serviceName = dbClientService(dbInstance);
9090
if (null != serviceName) {
91-
span.setServiceName(serviceName);
91+
span.setServiceName(serviceName, component());
9292
}
9393
}
9494
return span;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void onURI(@Nonnull final AgentSpan span, @Nonnull final URI uri) {
1919
if (null != host && !host.isEmpty()) {
2020
span.setTag(Tags.PEER_HOSTNAME, host);
2121
if (Config.get().isHttpClientSplitByDomain() && host.charAt(0) >= 'A') {
22-
span.setServiceName(host);
22+
span.setServiceName(host, component());
2323
}
2424
if (port > 0) {
2525
setPeerPort(span, port);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BaseDecoratorTest extends DDSpecification {
3131
_ * span.setTag(_, _) // Want to allow other calls from child implementations.
3232
_ * span.setMeasured(true)
3333
_ * span.setMetric(_, _)
34-
_ * span.setServiceName(_)
34+
_ * span.setServiceName(_, _)
3535
_ * span.setOperationName(_)
3636
_ * span.setSamplingPriority(_)
3737
0 * _

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ClientDecoratorTest extends BaseDecoratorTest {
1919

2020
then:
2121
if (serviceName != null) {
22-
1 * span.setServiceName(serviceName)
22+
1 * span.setServiceName(serviceName, "test-component")
2323
}
2424
1 * span.setMeasured(true)
2525
1 * span.setTag(Tags.COMPONENT, "test-component")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DBTypeProcessingDatabaseClientDecoratorTest extends ClientDecoratorTest {
2020

2121
then:
2222
if (serviceName != null) {
23-
1 * span.setServiceName(serviceName)
23+
1 * span.setServiceName(serviceName, "test-component")
2424
}
2525
1 * span.setMeasured(true)
2626
1 * span.setTag(Tags.COMPONENT, "test-component")

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
2323

2424
then:
2525
if (serviceName != null) {
26-
1 * span.setServiceName(serviceName)
26+
1 * span.setServiceName(serviceName, "test-component")
2727
}
2828
1 * span.setMeasured(true)
2929
1 * span.setTag(Tags.COMPONENT, "test-component")
@@ -58,11 +58,11 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
5858
1 * span.setTag(Tags.PEER_HOSTNAME, session.hostname)
5959
}
6060
if (instanceTypeSuffix && renameByInstance && session.instance) {
61-
1 * span.setServiceName(session.instance + "-" + decorator.dbType())
61+
1 * span.setServiceName(session.instance + "-" + decorator.dbType(), _)
6262
} else if (renameByInstance && session.instance) {
63-
1 * span.setServiceName(session.instance)
63+
1 * span.setServiceName(session.instance, _)
6464
} else if (renameByHost) {
65-
1 * span.setServiceName(session.hostname)
65+
1 * span.setServiceName(session.hostname, _)
6666
}
6767
}
6868
0 * _

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
7272
1 * span.setTag(Tags.PEER_PORT, req.url.port)
7373
1 * span.setResourceName({ it as String == req.method.toUpperCase() + " " + req.path }, ResourceNamePriorities.HTTP_PATH_NORMALIZER)
7474
if (renameService) {
75-
1 * span.setServiceName(req.url.host)
75+
1 * span.setServiceName(req.url.host, _)
7676
}
7777
1 * span.traceConfig() >> AgentTracer.traceConfig()
7878
}
@@ -147,7 +147,7 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
147147

148148
then:
149149
if (expectedServiceName) {
150-
1 * span.setServiceName(expectedServiceName)
150+
1 * span.setServiceName(expectedServiceName, _)
151151
}
152152
if (url != null) {
153153
1 * span.setResourceName(_, _)

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/InstrumentationSpecification.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import datadog.trace.agent.tooling.bytebuddy.matcher.ClassLoaderMatchers
4141
import datadog.trace.agent.tooling.bytebuddy.matcher.GlobalIgnores
4242
import datadog.trace.api.Config
4343
import datadog.trace.api.IdGenerationStrategy
44+
import datadog.trace.api.Pair
4445
import datadog.trace.api.ProcessTags
4546
import datadog.trace.api.TraceConfig
4647
import datadog.trace.api.config.GeneralConfig
@@ -240,7 +241,7 @@ abstract class InstrumentationSpecification extends DDSpecification implements A
240241
return null
241242
}
242243
@Override
243-
String getPreferredServiceName() {
244+
Pair<String, CharSequence> getPreferredServiceNameAndSource() {
244245
return null
245246
}
246247

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/TrackingSpanDecorator.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink
1313
import datadog.trace.core.DDSpan
1414

1515
import java.util.concurrent.ConcurrentHashMap
16+
import javax.annotation.Nonnull
1617

1718
/**
1819
* Decorator for {@link AgentSpan} that keeps track of the decorated span's finish location.
@@ -344,6 +345,11 @@ class TrackingSpanDecorator implements AgentSpan {
344345
return delegate.setServiceName(serviceName)
345346
}
346347

348+
@Override
349+
void setServiceName(@Nonnull String serviceName, @Nonnull CharSequence source) {
350+
delegate.setServiceName(serviceName, source)
351+
}
352+
347353
@Override
348354
CharSequence getResourceName() {
349355
return delegate.getResourceName()

0 commit comments

Comments
 (0)