Skip to content

Commit 86d12e2

Browse files
committed
Process 'sampling.priority' tags
1 parent d3eae46 commit 86d12e2

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

dd-trace-core/src/main/java/datadog/trace/core/taginterceptor/RuleFlags.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum Feature {
1414
DB_STATEMENT("DBStatementRule"),
1515
FORCE_MANUAL_DROP("ForceManualDropTagInterceptor"),
1616
FORCE_MANUAL_KEEP("ForceManualKeepTagInterceptor"),
17+
FORCE_SAMPLING_PRIORITY("ForceSamplingPriorityTagInterceptor"),
1718
PEER_SERVICE("PeerServiceTagInterceptor", false),
1819
SERVICE_NAME("ServiceNameTagInterceptor"),
1920
SERVLET_CONTEXT("ServletContextTagInterceptor");

dd-trace-core/src/main/java/datadog/trace/core/taginterceptor/TagInterceptor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import static datadog.trace.api.DDTags.ORIGIN_KEY;
66
import static datadog.trace.api.DDTags.SPAN_TYPE;
77
import static datadog.trace.api.sampling.PrioritySampling.USER_DROP;
8+
import static datadog.trace.api.sampling.PrioritySampling.USER_KEEP;
89
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_METHOD;
910
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_STATUS;
1011
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_URL;
1112
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.FORCE_MANUAL_DROP;
13+
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.FORCE_SAMPLING_PRIORITY;
1214
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.PEER_SERVICE;
1315
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.RESOURCE_NAME;
1416
import static datadog.trace.core.taginterceptor.RuleFlags.Feature.SERVICE_NAME;
@@ -98,6 +100,8 @@ public boolean interceptTag(DDSpanContext span, String tag, Object value) {
98100
case DDTags.MANUAL_DROP:
99101
return interceptSamplingPriority(
100102
FORCE_MANUAL_DROP, USER_DROP, SamplingMechanism.MANUAL, span, value);
103+
case Tags.SAMPLING_PRIORITY:
104+
return interceptSamplingPriority(span, value);
101105
case InstrumentationTags.SERVLET_CONTEXT:
102106
return interceptServletContext(span, value);
103107
case SPAN_TYPE:
@@ -241,6 +245,18 @@ private boolean interceptSamplingPriority(
241245
return false;
242246
}
243247

248+
private boolean interceptSamplingPriority(DDSpanContext span, Object value) {
249+
if (ruleFlags.isEnabled(FORCE_SAMPLING_PRIORITY)) {
250+
Number samplingPriority = getOrTryParse(value);
251+
if (null != samplingPriority) {
252+
span.setSamplingPriority(
253+
samplingPriority.intValue() > 0 ? USER_KEEP : USER_DROP, SamplingMechanism.MANUAL);
254+
}
255+
return true;
256+
}
257+
return false;
258+
}
259+
244260
private boolean interceptServletContext(DDSpanContext span, Object value) {
245261
// even though this tag is sometimes used to set the service name
246262
// (which has the side effect of marking the span as eligible for metrics

dd-trace-core/src/test/groovy/datadog/trace/core/taginterceptor/TagInterceptorTest.groovy

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,28 @@ class TagInterceptorTest extends DDCoreSpecification {
408408
tracer.close()
409409

410410
where:
411-
tag | value | expected
412-
DDTags.MANUAL_KEEP | true | PrioritySampling.USER_KEEP
413-
DDTags.MANUAL_KEEP | false | null
414-
DDTags.MANUAL_KEEP | "true" | PrioritySampling.USER_KEEP
415-
DDTags.MANUAL_KEEP | "false" | null
416-
DDTags.MANUAL_KEEP | "asdf" | null
417-
418-
DDTags.MANUAL_DROP | true | PrioritySampling.USER_DROP
419-
DDTags.MANUAL_DROP | false | null
420-
DDTags.MANUAL_DROP | "true" | PrioritySampling.USER_DROP
421-
DDTags.MANUAL_DROP | "false" | null
422-
DDTags.MANUAL_DROP | "asdf" | null
411+
tag | value | expected
412+
DDTags.MANUAL_KEEP | true | PrioritySampling.USER_KEEP
413+
DDTags.MANUAL_KEEP | false | null
414+
DDTags.MANUAL_KEEP | "true" | PrioritySampling.USER_KEEP
415+
DDTags.MANUAL_KEEP | "false" | null
416+
DDTags.MANUAL_KEEP | "asdf" | null
417+
418+
DDTags.MANUAL_DROP | true | PrioritySampling.USER_DROP
419+
DDTags.MANUAL_DROP | false | null
420+
DDTags.MANUAL_DROP | "true" | PrioritySampling.USER_DROP
421+
DDTags.MANUAL_DROP | "false" | null
422+
DDTags.MANUAL_DROP | "asdf" | null
423+
424+
Tags.SAMPLING_PRIORITY | -1 | PrioritySampling.USER_DROP
425+
Tags.SAMPLING_PRIORITY | 0 | PrioritySampling.USER_DROP
426+
Tags.SAMPLING_PRIORITY | 1 | PrioritySampling.USER_KEEP
427+
Tags.SAMPLING_PRIORITY | 2 | PrioritySampling.USER_KEEP
428+
Tags.SAMPLING_PRIORITY | "-1" | PrioritySampling.USER_DROP
429+
Tags.SAMPLING_PRIORITY | "0" | PrioritySampling.USER_DROP
430+
Tags.SAMPLING_PRIORITY | "1" | PrioritySampling.USER_KEEP
431+
Tags.SAMPLING_PRIORITY | "2" | PrioritySampling.USER_KEEP
432+
Tags.SAMPLING_PRIORITY | "asdf" | null
423433
}
424434

425435
def "set error flag when error tag reported"() {

0 commit comments

Comments
 (0)