Skip to content

Commit 521ee6a

Browse files
mccullsdevflow.devflow-routing-intake
andauthored
Remove AgentTracer.noopScope() sentinel (#12060)
Remove AgentTracer.noopScope() sentinel Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent f5472d9 commit 521ee6a

5 files changed

Lines changed: 14 additions & 28 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static datadog.trace.api.ConfigDefaults.DEFAULT_ASYNC_PROPAGATING;
44
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
5-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
65
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
76
import static datadog.trace.core.scopemanager.ContinuableScope.CONTEXT;
87
import static datadog.trace.core.scopemanager.ContinuableScope.INSTRUMENTATION;
@@ -25,6 +24,7 @@
2524
import datadog.trace.bootstrap.instrumentation.api.AgentTraceCollector;
2625
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
2726
import datadog.trace.bootstrap.instrumentation.api.NoopContinuation;
27+
import datadog.trace.bootstrap.instrumentation.api.NoopScope;
2828
import datadog.trace.bootstrap.instrumentation.api.ProfilerContext;
2929
import datadog.trace.bootstrap.instrumentation.api.ProfilingContextIntegration;
3030
import datadog.trace.core.monitor.HealthMetrics;
@@ -52,6 +52,7 @@ public final class ContinuableScopeManager {
5252
static final RatelimitedLogger ratelimitedLog = new RatelimitedLogger(log, 1, MINUTES);
5353

5454
private static final NoopContinuation ROOT_CONTINUATION = NoopContinuation.INSTANCE;
55+
private static final NoopScope INVALID_SCOPE = NoopScope.INSTANCE;
5556

5657
static final long iterationKeepAlive =
5758
SECONDS.toMillis(Config.get().getScopeIterationKeepAlive());
@@ -150,7 +151,7 @@ private AgentScope activate(
150151
if (depthLimit <= currentDepth) {
151152
healthMetrics.onScopeStackOverflow();
152153
log.debug("Scope depth limit exceeded ({}). Returning NoopScope.", currentDepth);
153-
return noopScope();
154+
return INVALID_SCOPE;
154155
}
155156
}
156157

@@ -187,7 +188,7 @@ private AgentScope activate(final Context context) {
187188
if (depthLimit <= currentDepth) {
188189
healthMetrics.onScopeStackOverflow();
189190
log.debug("Scope depth limit exceeded ({}). Returning NoopScope.", currentDepth);
190-
return noopScope();
191+
return INVALID_SCOPE;
191192
}
192193
}
193194

@@ -280,7 +281,7 @@ public AgentScope activateNext(final AgentSpan span) {
280281
if (hasDepthLimit && depthLimit <= currentDepth) {
281282
healthMetrics.onScopeStackOverflow();
282283
log.debug("Scope depth limit exceeded ({}). Returning NoopScope.", currentDepth);
283-
return noopScope();
284+
return INVALID_SCOPE;
284285
}
285286

286287
assert span != null;

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

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

3-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
4-
53
import datadog.context.Context;
64
import datadog.context.ContextScope;
75
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
86
import datadog.trace.bootstrap.instrumentation.api.AgentTraceCollector;
7+
import datadog.trace.bootstrap.instrumentation.api.NoopScope;
98
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
109

1110
/**
@@ -83,7 +82,7 @@ public ContextScope resume() {
8382
} else {
8483
// continuation cancelled or too many activations; rollback count
8584
COUNT.decrementAndGet(this);
86-
return noopScope();
85+
return NoopScope.INSTANCE;
8786
}
8887
}
8988

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

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

3-
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
43
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
54
import static org.junit.jupiter.api.Assertions.assertEquals;
65
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
7-
import static org.junit.jupiter.api.Assertions.assertNotSame;
8-
import static org.junit.jupiter.api.Assertions.assertSame;
96

107
import datadog.trace.api.config.TracerConfig;
118
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
129
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
10+
import datadog.trace.bootstrap.instrumentation.api.NoopScope;
1311
import datadog.trace.common.writer.ListWriter;
1412
import datadog.trace.core.CoreTracer;
1513
import datadog.trace.core.DDCoreJavaSpecification;
@@ -43,13 +41,13 @@ void scopeManagerReturnsNoopScopeIfDepthExceeded() {
4341
scope = tracer.activateSpan(span);
4442

4543
// a noop instance is returned
46-
assertSame(noopScope(), scope);
44+
assertInstanceOf(NoopScope.class, scope);
4745

4846
// activate a noop scope over the limit
4947
scope = scopeManager.activateManualSpan(noopSpan());
5048

5149
// still have a noop instance
52-
assertSame(noopScope(), scope);
50+
assertInstanceOf(NoopScope.class, scope);
5351

5452
// scope stack not effected
5553
assertEquals(depth, scopeManager.scopeStack().depth());
@@ -83,14 +81,14 @@ void scopeManagerIgnoresDepthLimitWhenZero() {
8381
scope = tracer.activateSpan(span);
8482

8583
// a real scope is returned
86-
assertNotSame(noopScope(), scope);
84+
assertInstanceOf(ContinuableScope.class, scope);
8785
assertEquals(defaultLimit + 1, scopeManager.scopeStack().depth());
8886

8987
// activate a noop span
9088
scope = scopeManager.activateManualSpan(noopSpan());
9189

9290
// a real instance is still returned
93-
assertNotSame(noopScope(), scope);
91+
assertInstanceOf(ContinuableScope.class, scope);
9492

9593
// scope stack not effected
9694
assertEquals(defaultLimit + 2, scopeManager.scopeStack().depth());

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,6 @@ public static AgentSpanContext noopSpanContext() {
224224
return NoopSpanContext.INSTANCE;
225225
}
226226

227-
/**
228-
* Returns the noop scope instance.
229-
*
230-
* <p>This instance will always be the same, and can be safely tested using object identity (ie
231-
* {@code ==}).
232-
*
233-
* @return the noop scope instance.
234-
*/
235-
public static AgentScope noopScope() {
236-
return NoopScope.INSTANCE;
237-
}
238-
239227
public static final TracerAPI NOOP_TRACER = new NoopTracerAPI();
240228

241229
private static volatile TracerAPI provider = NOOP_TRACER;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import datadog.trace.context.TraceScope;
44

5-
final class NoopScope implements AgentScope {
6-
static final NoopScope INSTANCE = new NoopScope();
5+
public final class NoopScope implements AgentScope {
6+
public static final NoopScope INSTANCE = new NoopScope();
77

88
private NoopScope() {}
99

0 commit comments

Comments
 (0)