Skip to content

Commit c7e8d53

Browse files
committed
feat(core): Rename AgentSpanContext.noop() into AgentSpanContext.noopSpanContext()
The goal is to normalize the API
1 parent 696d319 commit c7e8d53

File tree

10 files changed

+31
-24
lines changed

10 files changed

+31
-24
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.instrumentation.opentelemetry;
22

33
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
45

56
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
67
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -18,7 +19,7 @@ public class TypeConverter {
1819

1920
public TypeConverter() {
2021
noopSpanWrapper = new OtelSpan(noopSpan(), this);
21-
noopContextWrapper = new OtelSpanContext(AgentSpanContext.noop());
22+
noopContextWrapper = new OtelSpanContext(noopSpanContext());
2223
noopScopeWrapper = new OtelScope(AgentScope.noop());
2324
}
2425

@@ -74,7 +75,7 @@ public SpanContext toSpanContext(final AgentSpanContext context) {
7475
return null;
7576
}
7677
// avoid a new SpanContext wrapper allocation for the noop context
77-
if (context == AgentSpanContext.noop()) {
78+
if (context == noopSpanContext()) {
7879
return noopContextWrapper;
7980
}
8081
return new OtelSpanContext(context);
@@ -84,6 +85,6 @@ public AgentSpanContext toContext(final SpanContext spanContext) {
8485
if (spanContext instanceof OtelSpanContext) {
8586
return ((OtelSpanContext) spanContext).getDelegate();
8687
}
87-
return null == spanContext ? null : AgentSpanContext.noop();
88+
return null == spanContext ? null : noopSpanContext();
8889
}
8990
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import datadog.trace.api.DDTraceId
44
import datadog.trace.api.sampling.PrioritySampling
55
import datadog.trace.bootstrap.instrumentation.api.AgentScope
66
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
7-
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext
87
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
98
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
109
import datadog.trace.core.DDSpan
@@ -14,6 +13,8 @@ import datadog.trace.core.propagation.PropagationTags
1413
import datadog.trace.core.scopemanager.ContinuableScopeManager
1514
import datadog.trace.instrumentation.opentelemetry.TypeConverter
1615

16+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
17+
1718
class TypeConverterTest extends AgentTestRunner {
1819
TypeConverter typeConverter = new TypeConverter()
1920

@@ -35,7 +36,7 @@ class TypeConverterTest extends AgentTestRunner {
3536
}
3637

3738
def "should avoid the noop context wrapper allocation"() {
38-
def noopContext = AgentSpanContext.noop()
39+
def noopContext = noopSpanContext()
3940
expect:
4041
typeConverter.toSpanContext(noopContext) is typeConverter.toSpanContext(noopContext)
4142
}

dd-java-agent/instrumentation/opentracing/api-0.31/src/main/java/datadog/trace/instrumentation/opentracing31/TypeConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.instrumentation.opentracing31;
22

33
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
45

56
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
67
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -21,7 +22,7 @@ public class TypeConverter {
2122
public TypeConverter(final LogHandler logHandler) {
2223
this.logHandler = logHandler;
2324
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
24-
noopContextWrapper = new OTSpanContext(AgentSpanContext.noop());
25+
noopContextWrapper = new OTSpanContext(noopSpanContext());
2526
noopScopeWrapper = new OTScopeManager.OTScope(AgentScope.noop(), false, this);
2627
}
2728

@@ -80,7 +81,7 @@ public SpanContext toSpanContext(final AgentSpanContext context) {
8081
return null;
8182
}
8283
// avoid a new SpanContext wrapper allocation for the noop context
83-
if (context == AgentSpanContext.noop()) {
84+
if (context == noopSpanContext()) {
8485
return noopContextWrapper;
8586
}
8687
return new OTSpanContext(context);
@@ -90,6 +91,6 @@ public AgentSpanContext toContext(final SpanContext spanContext) {
9091
if (spanContext instanceof OTSpanContext) {
9192
return ((OTSpanContext) spanContext).getDelegate();
9293
}
93-
return null == spanContext ? null : AgentSpanContext.noop();
94+
return null == spanContext ? null : noopSpanContext();
9495
}
9596
}

dd-java-agent/instrumentation/opentracing/api-0.31/src/test/groovy/TypeConverterTest.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import datadog.trace.api.DDTraceId
44
import datadog.trace.api.sampling.PrioritySampling
55
import datadog.trace.bootstrap.instrumentation.api.AgentScope
66
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
7-
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext
87
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
98
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
109
import datadog.trace.core.DDSpan
@@ -15,6 +14,8 @@ import datadog.trace.core.scopemanager.ContinuableScopeManager
1514
import datadog.trace.instrumentation.opentracing.DefaultLogHandler
1615
import datadog.trace.instrumentation.opentracing31.TypeConverter
1716

17+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
18+
1819
class TypeConverterTest extends AgentTestRunner {
1920
TypeConverter typeConverter = new TypeConverter(new DefaultLogHandler())
2021

@@ -36,7 +37,7 @@ class TypeConverterTest extends AgentTestRunner {
3637
}
3738

3839
def "should avoid the noop context wrapper allocation"() {
39-
def noopContext = AgentSpanContext.noop()
40+
def noopContext = noopSpanContext()
4041
expect:
4142
typeConverter.toSpanContext(noopContext) is typeConverter.toSpanContext(noopContext)
4243
}

dd-java-agent/instrumentation/opentracing/api-0.32/src/main/java/datadog/trace/instrumentation/opentracing32/TypeConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.instrumentation.opentracing32;
22

33
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
45

56
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
67
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -21,7 +22,7 @@ public class TypeConverter {
2122
public TypeConverter(final LogHandler logHandler) {
2223
this.logHandler = logHandler;
2324
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
24-
noopContextWrapper = new OTSpanContext(AgentSpanContext.noop());
25+
noopContextWrapper = new OTSpanContext(noopSpanContext());
2526
noopScopeWrapper = new OTScopeManager.OTScope(AgentScope.noop(), false, this);
2627
}
2728

@@ -80,7 +81,7 @@ public SpanContext toSpanContext(final AgentSpanContext context) {
8081
return null;
8182
}
8283
// avoid a new SpanContext wrapper allocation for the noop context
83-
if (context == AgentSpanContext.noop()) {
84+
if (context == noopSpanContext()) {
8485
return noopContextWrapper;
8586
}
8687
return new OTSpanContext(context);
@@ -90,6 +91,6 @@ public AgentSpanContext toContext(final SpanContext spanContext) {
9091
if (spanContext instanceof OTSpanContext) {
9192
return ((OTSpanContext) spanContext).getDelegate();
9293
}
93-
return null == spanContext ? null : AgentSpanContext.noop();
94+
return null == spanContext ? null : noopSpanContext();
9495
}
9596
}

dd-java-agent/instrumentation/opentracing/api-0.32/src/test/groovy/TypeConverterTest.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import datadog.trace.api.DDTraceId
44
import datadog.trace.api.sampling.PrioritySampling
55
import datadog.trace.bootstrap.instrumentation.api.AgentScope
66
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
7-
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext
87
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
98
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
109
import datadog.trace.core.DDSpan
@@ -15,6 +14,8 @@ import datadog.trace.core.scopemanager.ContinuableScopeManager
1514
import datadog.trace.instrumentation.opentracing.DefaultLogHandler
1615
import datadog.trace.instrumentation.opentracing32.TypeConverter
1716

17+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
18+
1819
class TypeConverterTest extends AgentTestRunner {
1920
TypeConverter typeConverter = new TypeConverter(new DefaultLogHandler())
2021

@@ -36,7 +37,7 @@ class TypeConverterTest extends AgentTestRunner {
3637
}
3738

3839
def "should avoid the noop context wrapper allocation"() {
39-
def noopContext = AgentSpanContext.noop()
40+
def noopContext = noopSpanContext()
4041
expect:
4142
typeConverter.toSpanContext(noopContext) is typeConverter.toSpanContext(noopContext)
4243
}

dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/SpanPointersProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package datadog.trace.core.tagprocessor;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanLink.DEFAULT_FLAGS;
35
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.AWS_BUCKET_NAME;
46
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.AWS_OBJECT_KEY;
57
import static datadog.trace.bootstrap.instrumentation.api.InstrumentationTags.S3_ETAG;
68

7-
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
89
import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink;
910
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes;
1011
import datadog.trace.bootstrap.instrumentation.api.SpanLink;
@@ -57,8 +58,7 @@ public Map<String, Object> processTags(
5758
.put("link.kind", LINK_KIND)
5859
.build();
5960

60-
AgentSpanContext zeroContext = AgentSpanContext.noop();
61-
AgentSpanLink link = SpanLink.from(zeroContext, AgentSpanLink.DEFAULT_FLAGS, "", attributes);
61+
AgentSpanLink link = SpanLink.from(noopSpanContext(), DEFAULT_FLAGS, "", attributes);
6262
spanLinks.add(link);
6363
} catch (Exception e) {
6464
LOG.debug("Failed to add span pointer: {}", e.getMessage());

dd-trace-ot/src/main/java/datadog/opentracing/TypeConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.opentracing;
22

33
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
45

56
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
67
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
@@ -20,7 +21,7 @@ class TypeConverter {
2021
public TypeConverter(final LogHandler logHandler) {
2122
this.logHandler = logHandler;
2223
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
23-
noopContextWrapper = new OTSpanContext(AgentSpanContext.noop());
24+
noopContextWrapper = new OTSpanContext(noopSpanContext());
2425
noopScopeWrapper = new OTScopeManager.OTScope(AgentScope.noop(), false, this);
2526
}
2627

@@ -83,7 +84,7 @@ public SpanContext toSpanContext(final AgentSpanContext context) {
8384
return null;
8485
}
8586
// avoid a new SpanContext wrapper allocation for the noop context
86-
if (context == AgentSpanContext.noop()) {
87+
if (context == noopSpanContext()) {
8788
return noopContextWrapper;
8889
}
8990
return new OTSpanContext(context);
@@ -95,7 +96,7 @@ public AgentSpanContext toContext(final SpanContext spanContext) {
9596
} else if (spanContext instanceof OTSpanContext) {
9697
return ((OTSpanContext) spanContext).getDelegate();
9798
} else {
98-
return AgentSpanContext.noop();
99+
return noopSpanContext();
99100
}
100101
}
101102
}

dd-trace-ot/src/test/groovy/datadog/opentracing/TypeConverterTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import datadog.trace.api.DDTraceId
55
import datadog.trace.api.sampling.PrioritySampling
66
import datadog.trace.bootstrap.instrumentation.api.AgentScope
77
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
8-
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext
98
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
109
import datadog.trace.core.CoreTracer
1110
import datadog.trace.core.DDSpan
@@ -15,6 +14,7 @@ import datadog.trace.core.propagation.PropagationTags
1514
import datadog.trace.core.scopemanager.ContinuableScopeManager
1615
import datadog.trace.test.util.DDSpecification
1716

17+
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
1818
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
1919

2020
class TypeConverterTest extends DDSpecification {
@@ -38,7 +38,7 @@ class TypeConverterTest extends DDSpecification {
3838
}
3939

4040
def "should avoid the noop context wrapper allocation"() {
41-
def noopContext = AgentSpanContext.noop()
41+
def noopContext = noopSpanContext()
4242
expect:
4343
typeConverter.toSpanContext(noopContext) is typeConverter.toSpanContext(noopContext)
4444
}

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentSpanContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface AgentSpanContext {
2121
*
2222
* @return the noop scope instance.
2323
*/
24-
static AgentSpanContext noop() {
24+
static AgentSpanContext noopSpanContext() {
2525
return NoopSpanContext.INSTANCE;
2626
}
2727

0 commit comments

Comments
 (0)