Skip to content
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

don't notify scope listeners if trace is eligible for dropping #2661

Merged
merged 2 commits into from
May 4, 2021
Merged
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
11 changes: 11 additions & 0 deletions dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ public final DDSpan setResourceName(final CharSequence resourceName) {
return this;
}

@Override
public boolean eligibleForDropping() {
switch (context.getSamplingPriority()) {
case PrioritySampling.USER_DROP:
case PrioritySampling.SAMPLER_DROP:
return !context.getErrorFlag() & !forceKeep;
default:
return false;
}
}

/**
* Set the sampling priority of the root span of this span's trace
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static final class ContinuableScope implements AgentScope {
/** Flag to propagate this scope across async boundaries. */
private boolean isAsyncPropagating;

private final byte source;
private byte flags;

private short referenceCount = 1;

Expand All @@ -194,7 +194,7 @@ private static final class ContinuableScope implements AgentScope {
this.span = span;
this.scopeManager = scopeManager;
this.continuation = continuation;
this.source = source;
this.flags = source;
}

@Override
Expand All @@ -210,7 +210,7 @@ public void close() {

scopeManager.statsDClient.incrementCounter("scope.close.error");

if (source == ScopeSource.MANUAL.id()) {
if (source() == ScopeSource.MANUAL.id()) {
scopeManager.statsDClient.incrementCounter("scope.user.close.error");

if (scopeManager.strictMode) {
Expand Down Expand Up @@ -247,7 +247,7 @@ final void onProperClose() {
}
}

if (span instanceof NoopAgentSpan) {
if (!notifiedOnActivate()) {
return;
}

Expand Down Expand Up @@ -297,7 +297,7 @@ public void setAsyncPropagation(final boolean value) {
@Override
public ContinuableScopeManager.Continuation capture() {
return isAsyncPropagating
? new SingleContinuation(scopeManager, span, source).register()
? new SingleContinuation(scopeManager, span, source()).register()
: null;
}

Expand All @@ -309,7 +309,7 @@ public ContinuableScopeManager.Continuation capture() {
@Override
public ContinuableScopeManager.Continuation captureConcurrent() {
return isAsyncPropagating
? new ConcurrentContinuation(scopeManager, span, source).register()
? new ConcurrentContinuation(scopeManager, span, source()).register()
: null;
}

Expand All @@ -327,9 +327,10 @@ public void afterActivated() {
}
}

if (span instanceof NoopAgentSpan) {
if (span.eligibleForDropping()) {
return;
}
flags |= 0x80;

for (final ExtendedScopeListener listener : scopeManager.extendedScopeListeners) {
try {
Expand All @@ -339,6 +340,14 @@ public void afterActivated() {
}
}
}

private byte source() {
return (byte) (flags & 0x7F);
}

private boolean notifiedOnActivate() {
return flags < 0;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public interface AgentSpan extends MutableSpan {
@Override
AgentSpan setResourceName(final CharSequence resourceName);

boolean eligibleForDropping();

interface Context {
DDId getTraceId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ public AgentSpan setResourceName(final CharSequence resourceName) {
return this;
}

@Override
public boolean eligibleForDropping() {
return true;
}

@Override
public Integer getSamplingPriority() {
return (int) PrioritySampling.UNSET;
Expand Down