Skip to content

Commit 00fa9fd

Browse files
committed
oh!
Signed-off-by: sezen.leblay <sezen.leblay@datadoghq.com>
1 parent c513eb6 commit 00fa9fd

6 files changed

Lines changed: 17 additions & 5 deletions

File tree

dd-java-agent/appsec/src/main/java/com/datadog/appsec/ddwaf/WAFModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ public void onDataAvailable(
404404
// Keep event related span, because it could be ignored in case of
405405
// reduced datadog sampling rate.
406406
activeSpan.getLocalRootSpan().setTag(DDTags.MANUAL_KEEP, true);
407-
} else if (resultWithData.events) {
408-
activeSpan.getLocalRootSpan().setTag(Tags.ASM_KEEP, true);
407+
} else if (resultWithData.events) { // sampler still might keep
408+
activeSpan.getLocalRootSpan().setTag(DDTags.ASM_SAMPLER_KEEP, true);
409409
}
410410
activeSpan
411411
.getLocalRootSpan()

dd-java-agent/appsec/src/main/java/com/datadog/appsec/gateway/GatewayBridge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
754754
traceSeg.setTagTop(DDTags.MANUAL_KEEP, true);
755755
} else {
756756
// Set asm keep in case that root span was not available when events are detected
757-
traceSeg.setTagTop(Tags.ASM_KEEP, true);
757+
traceSeg.setTagTop(DDTags.ASM_SAMPLER_KEEP, true);
758758
}
759759
traceSeg.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTraceSource.ASM);
760760
traceSeg.setTagTop("appsec.event", true);

dd-smoke-tests/appsec/springboot/src/test/groovy/datadog/smoketest/appsec/TraceTaggingSmokeTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ class TraceTaggingSmokeTest extends AbstractAppSecServerSmokeTest {
330330
assert appsecJson.triggers != null, "Missing triggers in WAF attack event"
331331

332332
// Should NOT have USER_KEEP sampling priority since keep: false
333-
assert rootSpan.metrics.get('_sampling_priority_v1') < 2, "Should not have USER_KEEP sampling priority when keep: false"
333+
assert rootSpan.metrics.get('_sampling_priority_v1') < 2,
334+
"Should not have USER_KEEP sampling priority when keep: false"
334335

335336
}
336337

dd-trace-api/src/main/java/datadog/trace/api/DDTags.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public class DDTags {
5959
/** Manually force tracer to drop the trace */
6060
public static final String MANUAL_DROP = "manual.drop";
6161

62+
/** ASM force tracer to keep the trace with sampler priority (SAMPLER_KEEP) */
63+
public static final String ASM_SAMPLER_KEEP = "asm.sampler.keep";
64+
6265
public static final String TRACE_START_TIME = "t0";
6366

6467
/* Tags below are for internal use only. */

dd-trace-core/src/main/java/datadog/trace/common/sampling/AsmStandaloneSampler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public <T extends CoreSpan<T>> boolean sample(final T span) {
4141
public <T extends CoreSpan<T>> void setSamplingPriority(final T span) {
4242

4343
if (shouldSample()) {
44-
log.debug("Set SAMPLER_KEEP for span {}", span.getSpanId());
44+
log.debug("Set USER_KEEP for span {}", span.getSpanId());
4545
span.setSamplingPriority(SAMPLER_KEEP, SamplingMechanism.APPSEC);
4646
} else {
4747
log.debug("Set SAMPLER_DROP for span {}", span.getSpanId());

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static datadog.trace.api.DDTags.MEASURED;
55
import static datadog.trace.api.DDTags.ORIGIN_KEY;
66
import static datadog.trace.api.DDTags.SPAN_TYPE;
7+
import static datadog.trace.api.sampling.PrioritySampling.SAMPLER_KEEP;
78
import static datadog.trace.api.sampling.PrioritySampling.USER_DROP;
89
import static datadog.trace.api.sampling.PrioritySampling.USER_KEEP;
910
import static datadog.trace.bootstrap.instrumentation.api.Tags.HTTP_METHOD;
@@ -108,6 +109,7 @@ public boolean needsIntercept(String tag) {
108109
case DDTags.MANUAL_KEEP:
109110
case DDTags.MANUAL_DROP:
110111
case Tags.ASM_KEEP:
112+
case DDTags.ASM_SAMPLER_KEEP:
111113
case Tags.SAMPLING_PRIORITY:
112114
case Tags.PROPAGATED_TRACE_SOURCE:
113115
case Tags.PROPAGATED_DEBUG:
@@ -155,6 +157,12 @@ public boolean interceptTag(DDSpanContext span, String tag, Object value) {
155157
return true;
156158
}
157159
return false;
160+
case DDTags.ASM_SAMPLER_KEEP:
161+
if (asBoolean(value)) {
162+
span.setSamplingPriority(SAMPLER_KEEP, SamplingMechanism.APPSEC);
163+
return true;
164+
}
165+
return false;
158166
case Tags.SAMPLING_PRIORITY:
159167
return interceptSamplingPriority(span, value);
160168
case Tags.PROPAGATED_TRACE_SOURCE:

0 commit comments

Comments
 (0)