Skip to content

Commit d7acd78

Browse files
committed
feat(core): Rename AgentScope.noop() into AgentScope.noopScope()
The goal is to normalize the API
1 parent a8ce0d6 commit d7acd78

File tree

14 files changed

+36
-26
lines changed

14 files changed

+36
-26
lines changed

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

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

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
34
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
56

@@ -20,7 +21,7 @@ public class TypeConverter {
2021
public TypeConverter() {
2122
noopSpanWrapper = new OtelSpan(noopSpan(), this);
2223
noopContextWrapper = new OtelSpanContext(noopSpanContext());
23-
noopScopeWrapper = new OtelScope(AgentScope.noop());
24+
noopScopeWrapper = new OtelScope(noopScope());
2425
}
2526

2627
public AgentSpan toAgentSpan(final Span span) {
@@ -64,7 +65,7 @@ public Scope toScope(final AgentScope scope) {
6465
attachableScopeWrapper.attachWrapper(otScope);
6566
return otScope;
6667
}
67-
if (scope == AgentScope.noop()) {
68+
if (scope == noopScope()) {
6869
return noopScopeWrapper;
6970
}
7071
return new OtelScope(scope);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import datadog.trace.agent.test.AgentTestRunner
22
import datadog.trace.api.DDSpanId
33
import datadog.trace.api.DDTraceId
44
import datadog.trace.api.sampling.PrioritySampling
5-
import datadog.trace.bootstrap.instrumentation.api.AgentScope
65
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
76
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
87
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
@@ -13,6 +12,7 @@ import datadog.trace.core.propagation.PropagationTags
1312
import datadog.trace.core.scopemanager.ContinuableScopeManager
1413
import datadog.trace.instrumentation.opentelemetry.TypeConverter
1514

15+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope
1616
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
1717

1818
class TypeConverterTest extends AgentTestRunner {
@@ -42,7 +42,7 @@ class TypeConverterTest extends AgentTestRunner {
4242
}
4343

4444
def "should avoid the noop scope wrapper allocation"() {
45-
def noopScope = AgentScope.noop()
45+
def noopScope = noopScope()
4646
expect:
4747
typeConverter.toScope(noopScope) is typeConverter.toScope(noopScope)
4848
}

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

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

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
34
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
56

@@ -23,7 +24,7 @@ public TypeConverter(final LogHandler logHandler) {
2324
this.logHandler = logHandler;
2425
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
2526
noopContextWrapper = new OTSpanContext(noopSpanContext());
26-
noopScopeWrapper = new OTScopeManager.OTScope(AgentScope.noop(), false, this);
27+
noopScopeWrapper = new OTScopeManager.OTScope(noopScope(), false, this);
2728
}
2829

2930
public AgentSpan toAgentSpan(final Span span) {
@@ -70,7 +71,7 @@ public Scope toScope(final AgentScope scope, final boolean finishSpanOnClose) {
7071
attachableScopeWrapper.attachWrapper(otScope);
7172
return otScope;
7273
}
73-
if (scope == AgentScope.noop()) {
74+
if (scope == noopScope()) {
7475
return noopScopeWrapper;
7576
}
7677
return new OTScopeManager.OTScope(scope, finishSpanOnClose, this);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import datadog.trace.agent.test.AgentTestRunner
22
import datadog.trace.api.DDSpanId
33
import datadog.trace.api.DDTraceId
44
import datadog.trace.api.sampling.PrioritySampling
5-
import datadog.trace.bootstrap.instrumentation.api.AgentScope
65
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
76
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
87
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
@@ -14,6 +13,7 @@ import datadog.trace.core.scopemanager.ContinuableScopeManager
1413
import datadog.trace.instrumentation.opentracing.DefaultLogHandler
1514
import datadog.trace.instrumentation.opentracing31.TypeConverter
1615

16+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope
1717
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
1818

1919
class TypeConverterTest extends AgentTestRunner {
@@ -43,7 +43,7 @@ class TypeConverterTest extends AgentTestRunner {
4343
}
4444

4545
def "should avoid the noop scope wrapper allocation"() {
46-
def noopScope = AgentScope.noop()
46+
def noopScope = noopScope()
4747
expect:
4848
typeConverter.toScope(noopScope, true) is typeConverter.toScope(noopScope, true)
4949
typeConverter.toScope(noopScope, false) is typeConverter.toScope(noopScope, false)

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

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

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
34
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
56

@@ -23,7 +24,7 @@ public TypeConverter(final LogHandler logHandler) {
2324
this.logHandler = logHandler;
2425
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
2526
noopContextWrapper = new OTSpanContext(noopSpanContext());
26-
noopScopeWrapper = new OTScopeManager.OTScope(AgentScope.noop(), false, this);
27+
noopScopeWrapper = new OTScopeManager.OTScope(noopScope(), false, this);
2728
}
2829

2930
public AgentSpan toAgentSpan(final Span span) {
@@ -70,7 +71,7 @@ public Scope toScope(final AgentScope scope, final boolean finishSpanOnClose) {
7071
attachableScopeWrapper.attachWrapper(otScope);
7172
return otScope;
7273
}
73-
if (scope == AgentScope.noop()) {
74+
if (scope == noopScope()) {
7475
return noopScopeWrapper;
7576
}
7677
return new OTScopeManager.OTScope(scope, finishSpanOnClose, this);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import datadog.trace.agent.test.AgentTestRunner
22
import datadog.trace.api.DDSpanId
33
import datadog.trace.api.DDTraceId
44
import datadog.trace.api.sampling.PrioritySampling
5-
import datadog.trace.bootstrap.instrumentation.api.AgentScope
65
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
76
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
87
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
@@ -14,6 +13,7 @@ import datadog.trace.core.scopemanager.ContinuableScopeManager
1413
import datadog.trace.instrumentation.opentracing.DefaultLogHandler
1514
import datadog.trace.instrumentation.opentracing32.TypeConverter
1615

16+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope
1717
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
1818

1919
class TypeConverterTest extends AgentTestRunner {
@@ -43,7 +43,7 @@ class TypeConverterTest extends AgentTestRunner {
4343
}
4444

4545
def "should avoid the noop scope wrapper allocation"() {
46-
def noopScope = AgentScope.noop()
46+
def noopScope = noopScope()
4747
expect:
4848
typeConverter.toScope(noopScope, true) is typeConverter.toScope(noopScope, true)
4949
typeConverter.toScope(noopScope, false) is typeConverter.toScope(noopScope, false)

dd-java-agent/instrumentation/vertx-web-3.4/src/main/java/datadog/trace/instrumentation/vertx_3_4/server/RouteHandlerWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.vertx_3_4.server;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
34
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
56
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
@@ -54,7 +55,7 @@ public void handle(final RoutingContext routingContext) {
5455

5556
updateRoutingContextWithRoute(routingContext);
5657
}
57-
try (final AgentScope scope = span != null ? activateSpan(span, true) : AgentScope.noop()) {
58+
try (final AgentScope scope = span != null ? activateSpan(span, true) : noopScope()) {
5859
try {
5960
actual.handle(routingContext);
6061
} catch (final Throwable t) {

dd-java-agent/instrumentation/vertx-web-4.0/src/main/java/datadog/trace/instrumentation/vertx_4_0/server/RouteHandlerWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.vertx_4_0.server;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
34
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
56
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
@@ -48,7 +49,7 @@ public void handle(final RoutingContext routingContext) {
4849
updateRoutingContextWithRoute(routingContext);
4950
}
5051

51-
try (final AgentScope scope = span != null ? activateSpan(span, true) : AgentScope.noop()) {
52+
try (final AgentScope scope = span != null ? activateSpan(span, true) : noopScope()) {
5253
try {
5354
actual.handle(routingContext);
5455
} catch (final Throwable t) {

dd-trace-core/src/main/java/datadog/trace/core/scopemanager/ContinuableScopeManager.java

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

33
import static datadog.trace.api.ConfigDefaults.DEFAULT_ASYNC_PROPAGATING;
4+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
56
import static java.util.concurrent.TimeUnit.MINUTES;
67
import static java.util.concurrent.TimeUnit.NANOSECONDS;
@@ -115,7 +116,7 @@ private AgentScope activate(
115116
if (depthLimit <= currentDepth) {
116117
healthMetrics.onScopeStackOverflow();
117118
log.debug("Scope depth limit exceeded ({}). Returning NoopScope.", currentDepth);
118-
return AgentScope.noop();
119+
return noopScope();
119120
}
120121

121122
assert span != null;
@@ -191,7 +192,7 @@ public AgentScope activateNext(final AgentSpan span) {
191192
if (depthLimit <= currentDepth) {
192193
healthMetrics.onScopeStackOverflow();
193194
log.debug("Scope depth limit exceeded ({}). Returning NoopScope.", currentDepth);
194-
return AgentScope.noop();
195+
return noopScope();
195196
}
196197

197198
assert span != null;

dd-trace-core/src/main/java/datadog/trace/core/scopemanager/ScopeContinuation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.core.scopemanager;
22

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
4+
35
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
46
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
57
import datadog.trace.bootstrap.instrumentation.api.AgentTraceCollector;
@@ -78,7 +80,7 @@ public AgentScope activate() {
7880
} else {
7981
// continuation cancelled or too many activations; rollback count
8082
COUNT.decrementAndGet(this);
81-
return AgentScope.noop();
83+
return noopScope();
8284
}
8385
}
8486

dd-trace-core/src/test/groovy/datadog/trace/core/scopemanager/ScopeManagerDepthTest.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import datadog.trace.bootstrap.instrumentation.api.ScopeSource
77
import datadog.trace.common.writer.ListWriter
88
import datadog.trace.core.test.DDCoreSpecification
99

10+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope
1011
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan
1112

1213
class ScopeManagerDepthTest extends DDCoreSpecification {
@@ -31,13 +32,13 @@ class ScopeManagerDepthTest extends DDCoreSpecification {
3132
scope = tracer.activateSpan(span)
3233

3334
then: "a noop instance is returned"
34-
scope == AgentScope.noop()
35+
scope == noopScope()
3536

3637
when: "activate a noop scope over the limit"
3738
scope = scopeManager.activate(noopSpan(), ScopeSource.MANUAL)
3839

3940
then: "still have a noop instance"
40-
scope == AgentScope.noop()
41+
scope == noopScope()
4142

4243
and: "scope stack not effected."
4344
scopeManager.scopeStack().depth() == depth
@@ -72,14 +73,14 @@ class ScopeManagerDepthTest extends DDCoreSpecification {
7273
scope = tracer.activateSpan(span)
7374

7475
then: "a real scope is returned"
75-
scope != AgentScope.noop()
76+
scope != noopScope()
7677
scopeManager.scopeStack().depth() == defaultLimit + 1
7778

7879
when: "activate a noop span"
7980
scope = scopeManager.activate(noopSpan(), ScopeSource.MANUAL)
8081

8182
then: "a real instance is still returned"
82-
scope != AgentScope.noop()
83+
scope != noopScope()
8384

8485
and: "scope stack not effected."
8586
scopeManager.scopeStack().depth() == defaultLimit + 2

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

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

3+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope;
34
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.noopSpan;
45
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext;
56

@@ -22,7 +23,7 @@ public TypeConverter(final LogHandler logHandler) {
2223
this.logHandler = logHandler;
2324
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
2425
noopContextWrapper = new OTSpanContext(noopSpanContext());
25-
noopScopeWrapper = new OTScopeManager.OTScope(AgentScope.noop(), false, this);
26+
noopScopeWrapper = new OTScopeManager.OTScope(noopScope(), false, this);
2627
}
2728

2829
public AgentSpan toAgentSpan(final Span span) {
@@ -73,7 +74,7 @@ public Scope toScope(final AgentScope scope, final boolean finishSpanOnClose) {
7374
attachableScopeWrapper.attachWrapper(otScope);
7475
return otScope;
7576
}
76-
if (scope == AgentScope.noop()) {
77+
if (scope == noopScope()) {
7778
return noopScopeWrapper;
7879
}
7980
return new OTScopeManager.OTScope(scope, finishSpanOnClose, this);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package datadog.opentracing
33
import datadog.trace.api.DDSpanId
44
import datadog.trace.api.DDTraceId
55
import datadog.trace.api.sampling.PrioritySampling
6-
import datadog.trace.bootstrap.instrumentation.api.AgentScope
76
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
87
import datadog.trace.bootstrap.instrumentation.api.ScopeSource
98
import datadog.trace.core.CoreTracer
@@ -14,6 +13,7 @@ import datadog.trace.core.propagation.PropagationTags
1413
import datadog.trace.core.scopemanager.ContinuableScopeManager
1514
import datadog.trace.test.util.DDSpecification
1615

16+
import static datadog.trace.bootstrap.instrumentation.api.AgentScope.noopScope
1717
import static datadog.trace.bootstrap.instrumentation.api.AgentSpanContext.noopSpanContext
1818
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.NoopPathwayContext
1919

@@ -44,7 +44,7 @@ class TypeConverterTest extends DDSpecification {
4444
}
4545

4646
def "should avoid the noop scope wrapper allocation"() {
47-
def noopScope = AgentScope.noop()
47+
def noopScope = noopScope()
4848
expect:
4949
typeConverter.toScope(noopScope, true) is typeConverter.toScope(noopScope, true)
5050
typeConverter.toScope(noopScope, false) is typeConverter.toScope(noopScope, false)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface AgentScope extends TraceScope, Closeable {
1212
*
1313
* @return the noop scope instance.
1414
*/
15-
static AgentScope noop() {
15+
static AgentScope noopScope() {
1616
return NoopScope.INSTANCE;
1717
}
1818

0 commit comments

Comments
 (0)