Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum Feature {
DB_STATEMENT("DBStatementRule"),
FORCE_MANUAL_DROP("ForceManualDropTagInterceptor"),
FORCE_MANUAL_KEEP("ForceManualKeepTagInterceptor"),
FORCE_SAMPLING_PRIORITY("ForceSamplingPriorityTagInterceptor"),
PEER_SERVICE("PeerServiceTagInterceptor", false),
SERVICE_NAME("ServiceNameTagInterceptor"),
SERVLET_CONTEXT("ServletContextTagInterceptor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import static datadog.trace.api.DDTags.ORIGIN_KEY;
import static datadog.trace.api.DDTags.SPAN_TYPE;
import static datadog.trace.api.sampling.PrioritySampling.USER_DROP;
import static datadog.trace.api.sampling.PrioritySampling.USER_KEEP;
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_METHOD;
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_STATUS;
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_URL;
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.FORCE_MANUAL_DROP;
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.FORCE_SAMPLING_PRIORITY;
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.PEER_SERVICE;
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.RESOURCE_NAME;
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.SERVICE_NAME;
Expand Down Expand Up @@ -98,6 +100,8 @@ public boolean interceptTag(DDSpanContext span, String tag, Object value) {
case DDTags.MANUAL_DROP:
return interceptSamplingPriority(
FORCE_MANUAL_DROP, USER_DROP, SamplingMechanism.MANUAL, span, value);
case Tags.SAMPLING_PRIORITY:
return interceptSamplingPriority(span, value);
case InstrumentationTags.SERVLET_CONTEXT:
return interceptServletContext(span, value);
case SPAN_TYPE:
Expand Down Expand Up @@ -241,6 +245,18 @@ private boolean interceptSamplingPriority(
return false;
}

private boolean interceptSamplingPriority(DDSpanContext span, Object value) {
if (ruleFlags.isEnabled(FORCE_SAMPLING_PRIORITY)) {
Number samplingPriority = getOrTryParse(value);
if (null != samplingPriority) {
span.setSamplingPriority(
samplingPriority.intValue() > 0 ? USER_KEEP : USER_DROP, SamplingMechanism.MANUAL);
}
return true;
}
return false;
}

private boolean interceptServletContext(DDSpanContext span, Object value) {
// even though this tag is sometimes used to set the service name
// (which has the side effect of marking the span as eligible for metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,28 @@ class TagInterceptorTest extends DDCoreSpecification {
tracer.close()

where:
tag | value | expected
DDTags.MANUAL_KEEP | true | PrioritySampling.USER_KEEP
DDTags.MANUAL_KEEP | false | null
DDTags.MANUAL_KEEP | "true" | PrioritySampling.USER_KEEP
DDTags.MANUAL_KEEP | "false" | null
DDTags.MANUAL_KEEP | "asdf" | null

DDTags.MANUAL_DROP | true | PrioritySampling.USER_DROP
DDTags.MANUAL_DROP | false | null
DDTags.MANUAL_DROP | "true" | PrioritySampling.USER_DROP
DDTags.MANUAL_DROP | "false" | null
DDTags.MANUAL_DROP | "asdf" | null
tag | value | expected
DDTags.MANUAL_KEEP | true | PrioritySampling.USER_KEEP
DDTags.MANUAL_KEEP | false | null
DDTags.MANUAL_KEEP | "true" | PrioritySampling.USER_KEEP
DDTags.MANUAL_KEEP | "false" | null
DDTags.MANUAL_KEEP | "asdf" | null

DDTags.MANUAL_DROP | true | PrioritySampling.USER_DROP
DDTags.MANUAL_DROP | false | null
DDTags.MANUAL_DROP | "true" | PrioritySampling.USER_DROP
DDTags.MANUAL_DROP | "false" | null
DDTags.MANUAL_DROP | "asdf" | null

Tags.SAMPLING_PRIORITY | -1 | PrioritySampling.USER_DROP
Tags.SAMPLING_PRIORITY | 0 | PrioritySampling.USER_DROP
Tags.SAMPLING_PRIORITY | 1 | PrioritySampling.USER_KEEP
Tags.SAMPLING_PRIORITY | 2 | PrioritySampling.USER_KEEP
Tags.SAMPLING_PRIORITY | "-1" | PrioritySampling.USER_DROP
Tags.SAMPLING_PRIORITY | "0" | PrioritySampling.USER_DROP
Tags.SAMPLING_PRIORITY | "1" | PrioritySampling.USER_KEEP
Tags.SAMPLING_PRIORITY | "2" | PrioritySampling.USER_KEEP
Tags.SAMPLING_PRIORITY | "asdf" | null
}

def "set error flag when error tag reported"() {
Expand Down