Skip to content

Commit 97c4367

Browse files
committed
wip
1 parent 00f2141 commit 97c4367

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -828,13 +828,22 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
828828
} else {
829829
WafMetricCollector.get().wafRequest();
830830
}
831-
}
832831

833-
// API Security sampling requires http.route tag.
834-
final Object route = tags.get(Tags.HTTP_ROUTE);
835-
if (route instanceof String) {
836-
ctx.setRoute((String) route);
837-
requestSampler.preSampleRequest(ctx);
832+
// API Security sampling requires http.route tag.
833+
log.debug("Checking API Security for end of request handler on span: {}", spanInfo.getSpanId());
834+
Object route = tags.get(Tags.HTTP_ROUTE);
835+
if (route == null) {
836+
log.debug("No route tag found in the current span, checking root");
837+
route = traceSeg.getTagTop(Tags.HTTP_ROUTE);
838+
}
839+
if (route == null) {
840+
log.debug("No route tag found in the root span");
841+
} else if (route instanceof String) {
842+
ctx.setRoute((String) route);
843+
requestSampler.preSampleRequest(ctx);
844+
} else {
845+
log.debug("Route tag is not a string, skipping API Security sampling: {}", route.getClass().getSimpleName());
846+
}
838847
}
839848

840849
return NoopFlow.INSTANCE;

0 commit comments

Comments
 (0)