Skip to content
Open
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 @@ -2,7 +2,6 @@

import static datadog.trace.api.ConfigDefaults.DEFAULT_ASYNC_PROPAGATING;
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static datadog.trace.core.scopemanager.ContinuableScope.CONTEXT;
import static datadog.trace.core.scopemanager.ContinuableScope.INSTRUMENTATION;
Expand All @@ -25,6 +24,7 @@
import datadog.trace.bootstrap.instrumentation.api.AgentTraceCollector;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.NoopContinuation;
import datadog.trace.bootstrap.instrumentation.api.NoopScope;
import datadog.trace.bootstrap.instrumentation.api.ProfilerContext;
import datadog.trace.bootstrap.instrumentation.api.ProfilingContextIntegration;
import datadog.trace.core.monitor.HealthMetrics;
Expand Down Expand Up @@ -52,6 +52,7 @@ public final class ContinuableScopeManager {
static final RatelimitedLogger ratelimitedLog = new RatelimitedLogger(log, 1, MINUTES);

private static final NoopContinuation ROOT_CONTINUATION = NoopContinuation.INSTANCE;
private static final NoopScope INVALID_SCOPE = NoopScope.INSTANCE;

static final long iterationKeepAlive =
SECONDS.toMillis(Config.get().getScopeIterationKeepAlive());
Expand Down Expand Up @@ -150,7 +151,7 @@ private AgentScope activate(
if (depthLimit <= currentDepth) {
healthMetrics.onScopeStackOverflow();
log.debug("Scope depth limit exceeded ({}). Returning NoopScope.", currentDepth);
return noopScope();
return INVALID_SCOPE;
}
}

Expand Down Expand Up @@ -187,7 +188,7 @@ private AgentScope activate(final Context context) {
if (depthLimit <= currentDepth) {
healthMetrics.onScopeStackOverflow();
log.debug("Scope depth limit exceeded ({}). Returning NoopScope.", currentDepth);
return noopScope();
return INVALID_SCOPE;
}
}

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

assert span != null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package datadog.trace.core.scopemanager;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;

import datadog.context.Context;
import datadog.context.ContextScope;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentTraceCollector;
import datadog.trace.bootstrap.instrumentation.api.NoopScope;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
Expand Down Expand Up @@ -83,7 +82,7 @@ public ContextScope resume() {
} else {
// continuation cancelled or too many activations; rollback count
COUNT.decrementAndGet(this);
return noopScope();
return NoopScope.INSTANCE;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package datadog.trace.core.scopemanager;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;

import datadog.trace.api.config.TracerConfig;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.NoopScope;
import datadog.trace.common.writer.ListWriter;
import datadog.trace.core.CoreTracer;
import datadog.trace.core.DDCoreJavaSpecification;
Expand Down Expand Up @@ -43,13 +41,13 @@ void scopeManagerReturnsNoopScopeIfDepthExceeded() {
scope = tracer.activateSpan(span);

// a noop instance is returned
assertSame(noopScope(), scope);
assertInstanceOf(NoopScope.class, scope);

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

// still have a noop instance
assertSame(noopScope(), scope);
assertInstanceOf(NoopScope.class, scope);

// scope stack not effected
assertEquals(depth, scopeManager.scopeStack().depth());
Expand Down Expand Up @@ -83,14 +81,14 @@ void scopeManagerIgnoresDepthLimitWhenZero() {
scope = tracer.activateSpan(span);

// a real scope is returned
assertNotSame(noopScope(), scope);
assertInstanceOf(ContinuableScope.class, scope);
assertEquals(defaultLimit + 1, scopeManager.scopeStack().depth());

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

// a real instance is still returned
assertNotSame(noopScope(), scope);
assertInstanceOf(ContinuableScope.class, scope);

// scope stack not effected
assertEquals(defaultLimit + 2, scopeManager.scopeStack().depth());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,6 @@ public static AgentSpanContext noopSpanContext() {
return NoopSpanContext.INSTANCE;
}

Comment thread
mcculls marked this conversation as resolved.
/**
* Returns the noop scope instance.
*
* <p>This instance will always be the same, and can be safely tested using object identity (ie
* {@code ==}).
*
* @return the noop scope instance.
*/
public static AgentScope noopScope() {
return NoopScope.INSTANCE;
}

public static final TracerAPI NOOP_TRACER = new NoopTracerAPI();

private static volatile TracerAPI provider = NOOP_TRACER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import datadog.trace.context.TraceScope;

final class NoopScope implements AgentScope {
static final NoopScope INSTANCE = new NoopScope();
public final class NoopScope implements AgentScope {
Comment thread
mcculls marked this conversation as resolved.
public static final NoopScope INSTANCE = new NoopScope();

private NoopScope() {}

Expand Down
Loading