-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tracing libraries must configure the tracer sampling mechanism so tha…
…t, by default, 1 trace per minute gets sent.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dd-trace-core/src/main/java/datadog/trace/common/sampling/ServiceAsmTimeTraceSampler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package datadog.trace.common.sampling; | ||
|
||
import datadog.trace.api.sampling.SamplingMechanism; | ||
import datadog.trace.core.CoreSpan; | ||
import datadog.trace.core.util.SimpleRateLimiter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
|
||
public class ServiceAsmTimeTraceSampler implements Sampler, PrioritySampler { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ServiceAsmTimeTraceSampler.class); | ||
|
||
private final SimpleRateLimiter rateLimiter; | ||
|
||
public ServiceAsmTimeTraceSampler() { | ||
this.rateLimiter = new SimpleRateLimiter(60); //one per minute | ||
} | ||
|
||
@Override | ||
public <T extends CoreSpan<T>> boolean sample(final T span) { | ||
// Priority sampling sends all traces to the core agent, including traces marked dropped. | ||
// This allows the core agent to collect stats on all traces. | ||
return true; | ||
} | ||
|
||
@Override | ||
public <T extends CoreSpan<T>> void setSamplingPriority(final T span) { | ||
|
||
//TODO check how to short circuit this for ASM | ||
|
||
if (rateLimiter.tryAcquire()) { | ||
span.setSamplingPriority( | ||
PrioritySampling.SAMPLER_KEEP, | ||
SamplingMechanism.DEFAULT); | ||
} else { | ||
span.setSamplingPriority( | ||
PrioritySampling.SAMPLER_DROP, | ||
SamplingMechanism.DEFAULT); | ||
} | ||
|
||
} | ||
|
||
} |