Skip to content

Introducing an internal instrumentation component name #8708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -69,7 +69,9 @@ public AgentSpan afterStart(final AgentSpan span) {
if (spanType() != null) {
span.setSpanType(spanType());
}
span.setTag(Tags.COMPONENT, component());
final CharSequence component = component();
span.setTag(Tags.COMPONENT, component);
span.context().setInstrumentationComponentName(component);
if (traceAnalyticsEnabled) {
span.setMetric(DDTags.ANALYTICS_SAMPLE_RATE, traceAnalyticsSampleRate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datadog.trace.bootstrap.instrumentation.decorator


import datadog.trace.bootstrap.instrumentation.api.AgentSpan
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities
import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.test.util.DDSpecification
Expand All @@ -16,6 +17,7 @@ class BaseDecoratorTest extends DDSpecification {
def errorPriority = null as Byte

def span = Mock(AgentSpan)
def spanContext = Mock(AgentSpanContext)

def "test afterStart"() {
when:
Expand All @@ -24,6 +26,8 @@ class BaseDecoratorTest extends DDSpecification {
then:
1 * span.setSpanType(decorator.spanType())
1 * span.setTag(Tags.COMPONENT, "test-component")
1 * span.context() >> spanContext
1 * spanContext.setInstrumentationComponentName("test-component")
_ * span.setTag(_, _) // Want to allow other calls from child implementations.
_ * span.setMeasured(true)
_ * span.setMetric(_, _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datadog.trace.bootstrap.instrumentation.decorator

import datadog.trace.api.DDTags
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext
import datadog.trace.bootstrap.instrumentation.api.Tags

class ClientDecoratorTest extends BaseDecoratorTest {
Expand All @@ -11,6 +12,7 @@ class ClientDecoratorTest extends BaseDecoratorTest {
def "test afterStart"() {
setup:
def decorator = newDecorator((String) serviceName)
def spanContext = Mock(AgentSpanContext)

when:
decorator.afterStart(span)
Expand All @@ -21,6 +23,8 @@ class ClientDecoratorTest extends BaseDecoratorTest {
}
1 * span.setMeasured(true)
1 * span.setTag(Tags.COMPONENT, "test-component")
1 * span.context() >> spanContext
1 * spanContext.setInstrumentationComponentName("test-component")
1 * span.setTag(Tags.SPAN_KIND, "client")
1 * span.setSpanType(decorator.spanType())
1 * span.setMetric(DDTags.ANALYTICS_SAMPLE_RATE, 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class DBTypeProcessingDatabaseClientDecoratorTest extends ClientDecoratorTest {
}
1 * span.setMeasured(true)
1 * span.setTag(Tags.COMPONENT, "test-component")
1 * span.context() >> spanContext
1 * spanContext.setInstrumentationComponentName("test-component")
1 * span.setTag(Tags.SPAN_KIND, "client")
1 * span.setSpanType("test-type")
1 * span.setServiceName("test-db")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datadog.trace.bootstrap.instrumentation.decorator

import datadog.trace.api.DDTags
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext
import datadog.trace.bootstrap.instrumentation.api.Tags

import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_HOST
Expand All @@ -15,6 +16,7 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
def "test afterStart"() {
setup:
def decorator = newDecorator((String) serviceName)
def spanContext = Mock(AgentSpanContext)

when:
decorator.afterStart(span)
Expand All @@ -25,6 +27,8 @@ class DatabaseClientDecoratorTest extends ClientDecoratorTest {
}
1 * span.setMeasured(true)
1 * span.setTag(Tags.COMPONENT, "test-component")
1 * span.context() >> spanContext
1 * spanContext.setInstrumentationComponentName("test-component")
1 * span.setTag(Tags.SPAN_KIND, "client")
1 * span.setSpanType("test-type")
1 * span.setMetric(DDTags.ANALYTICS_SAMPLE_RATE, 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datadog.trace.bootstrap.instrumentation.decorator


import datadog.trace.bootstrap.instrumentation.api.AgentSpan
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext

import static datadog.trace.api.DDTags.ANALYTICS_SAMPLE_RATE
import static datadog.trace.api.DDTags.LANGUAGE_TAG_KEY
Expand All @@ -15,12 +16,16 @@ class ServerDecoratorTest extends BaseDecoratorTest {

def "test afterStart"() {
def decorator = newDecorator()
def spanContext = Mock(AgentSpanContext)

when:
decorator.afterStart(span)

then:
1 * span.setTag(LANGUAGE_TAG_KEY, LANGUAGE_TAG_VALUE)
1 * span.setTag(COMPONENT, "test-component")
1 * span.context() >> spanContext
1 * spanContext.setInstrumentationComponentName("test-component")
1 * span.setTag(SPAN_KIND, "server")
1 * span.setSpanType(decorator.spanType())
if (decorator.traceAnalyticsEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public AgentSpan afterStart(final AgentSpan span) {
span.setTag(DDTags.HOST_VCPU_COUNT, cpuCount);
span.setTag(Tags.TEST_TYPE, testType());
span.setTag(Tags.COMPONENT, component());
span.context().setInstrumentationComponentName(component());
span.setTag(Tags.TEST_SESSION_NAME, sessionName);

for (final Map.Entry<String, String> ciTag : ciTags.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestDecoratorImplTest extends Specification {
then:
1 * span.setTag(Tags.TEST_SESSION_NAME, "session-name")
1 * span.setTag(Tags.COMPONENT, "test-component")
1 * span.context().setInstrumentationComponentName("test-component")
1 * span.setTag(Tags.TEST_TYPE, decorator.testType())
1 * span.setSamplingPriority(PrioritySampling.SAMPLER_KEEP)
1 * span.setTag(DDTags.ORIGIN_KEY, decorator.origin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public OtelSpan(AgentSpan delegate) {
}
this.statusCode = UNSET;
this.recording = true;
delegate.context().setInstrumentationComponentName("opentelemetry");
}

public static Span invalid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private AgentSpan withQueryInfo(AgentSpan span, DBQueryInfo info, CharSequence c
} else {
span.setResourceName(DB_QUERY);
}
span.context().setInstrumentationComponentName(component);
return span.setTag(Tags.COMPONENT, component);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public boolean beforeStep(Step step, ScenarioRuntime sr) {
String stepName = step.getPrefix() + " " + step.getText();
span.setResourceName(stepName);
span.setTag(Tags.COMPONENT, "karate");
span.context().setInstrumentationComponentName("karate");
span.setTag("step.name", stepName);
span.setTag("step.startLine", step.getLine());
span.setTag("step.endLine", step.getEndLine());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public Span.Builder setStartTimestamp(final long startTimestamp) {

@Override
public Span startSpan() {
return converter.toSpan(delegate.start());
final AgentSpan agentSpan = delegate.start();
agentSpan.context().setInstrumentationComponentName("opentelemetry");
return converter.toSpan(agentSpan);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class OpenTelemetryTest extends AgentTestRunner {
}
defaultTags()
}
assert span.context().instrumentationComponentName == "opentelemetry"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ class OpenTelemetry14Test extends AgentTestRunner {
"empty-array" ""
}
}
assert span.context().instrumentationComponentName == "opentelemetry"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,15 @@ public Span startManual() {
@Override
public Span start() {
final AgentSpan agentSpan = delegate.start();
agentSpan.context().setInstrumentationComponentName("opentracing");
return converter.toSpan(agentSpan);
}

@Override
public Scope startActive(final boolean finishSpanOnClose) {
return converter.toScope(tracer.activateManualSpan(delegate.start()), finishSpanOnClose);
final AgentSpan agentSpan = delegate.start();
agentSpan.context().setInstrumentationComponentName("opentracing");
return converter.toScope(tracer.activateManualSpan(agentSpan), finishSpanOnClose);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class OpenTracing31Test extends AgentTestRunner {
}
defaultTags(addReference != null)
}
assert span.context().instrumentationComponentName == "opentracing"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ public Span startManual() {
@Override
public Span start() {
final AgentSpan agentSpan = delegate.start();
agentSpan.context().setInstrumentationComponentName("opentracing");
return converter.toSpan(agentSpan);
}

@Override
public Scope startActive(final boolean finishSpanOnClose) {
return converter.toScope(tracer.activateManualSpan(delegate.start()), finishSpanOnClose);
final AgentSpan agentSpan = delegate.start();
agentSpan.context().setInstrumentationComponentName("opentracing");
return converter.toScope(tracer.activateManualSpan(agentSpan), finishSpanOnClose);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class OpenTracing32Test extends AgentTestRunner {
}
defaultTags(addReference != null)
}
assert span.context().instrumentationComponentName == "opentracing"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public <T> AgentSpan startAndDecorateSpanForStatement(
span.setResourceName(DB_QUERY);
}
span.setTag(Tags.COMPONENT, component);

span.context().setInstrumentationComponentName(component);
return span;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class TagsAssert {
DDTags.REQUIRED_CODE_ORIGIN_TAGS.each {
assertedTags.add(it)
}
assertedTags.add(DDTags.INTEGRATION_COMPONENT)
if (tags[Tags.COMPONENT] != null) {
assert tags[Tags.COMPONENT] == tags[DDTags.INTEGRATION_COMPONENT]
}

assert tags["thread.name"] != null
assert tags["thread.id"] != null
Expand Down
1 change: 1 addition & 0 deletions dd-trace-api/src/main/java/datadog/trace/api/DDTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ public class DDTags {
public static final String DECISION_MAKER_INHERITED = "_dd.dm.inherited";
public static final String DECISION_MAKER_SERVICE = "_dd.dm.service";
public static final String DECISION_MAKER_RESOURCE = "_dd.dm.resource";
public static final String INTEGRATION_COMPONENT = "_dd.integration_component";
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class DDSpanContext
private final UTF8BytesString threadName;

private volatile short httpStatusCode;
private CharSequence instrumentationComponentName;

/**
* Tags are associated to the current span, they will not propagate to the children span.
Expand Down Expand Up @@ -878,6 +879,15 @@ public void processTagsAndBaggage(
}
}

@Override
public void setInstrumentationComponentName(CharSequence componentName) {
this.instrumentationComponentName = componentName;
}

public CharSequence getInstrumentationComponentName() {
return instrumentationComponentName;
}

@Override
public String toString() {
final StringBuilder s =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package datadog.trace.core.tagprocessor;

import static datadog.trace.api.DDTags.INTEGRATION_COMPONENT;

import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink;
import datadog.trace.core.DDSpanContext;
import java.util.List;
import java.util.Map;

public class InstrumentationComponentAdder implements TagsPostProcessor {

@Override
public Map<String, Object> processTags(
Map<String, Object> unsafeTags, DDSpanContext spanContext, List<AgentSpanLink> spanLinks) {
final CharSequence internalComponentName = spanContext.getInstrumentationComponentName();
if (internalComponentName != null) {
unsafeTags.put(INTEGRATION_COMPONENT, internalComponentName);
} else {
unsafeTags.remove(INTEGRATION_COMPONENT);
}
return unsafeTags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class TagsPostProcessorFactory {

private static class Lazy {
private static TagsPostProcessor create() {
final List<TagsPostProcessor> processors = new ArrayList<>(4);
final List<TagsPostProcessor> processors = new ArrayList<>(7);
processors.add(new PeerServiceCalculator());
if (addBaseService) {
processors.add(new BaseServiceAdder(Config.get().getServiceName()));
Expand All @@ -32,6 +32,7 @@ private static TagsPostProcessor create() {
if (Config.get().isAddSpanPointers("aws")) {
processors.add(new SpanPointersProcessor());
}
processors.add(new InstrumentationComponentAdder());
return new PostProcessorChain(
processors.toArray(processors.toArray(new TagsPostProcessor[0])));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package datadog.trace.core.tagprocessor


import datadog.trace.core.DDSpanContext
import datadog.trace.test.util.DDSpecification

class InstrumentationComponentAdderTest extends DDSpecification {
def "should add or remove _dd.integration_component when set (#isSet) on the span context"() {
setup:
def calculator = new InstrumentationComponentAdder()
def spanContext = Mock(DDSpanContext)

when:

def enrichedTags = calculator.processTags(["_dd.integration_component": "bad"], spanContext, [])

then:
1 * spanContext.getInstrumentationComponentName() >> (isSet ? "test" : null)

and:
assert enrichedTags == (isSet ? ["_dd.integration_component": "test"] : [:])

where:
isSet << [true, false]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public interface AgentSpanContext {

default void mergePathwayContext(PathwayContext pathwayContext) {}

default void setInstrumentationComponentName(CharSequence componentName) {}

/**
* Gets whether the span context used is part of the local trace or from another service
*
Expand Down
Loading