Skip to content

Commit 8333ddf

Browse files
committed
http route fallback
1 parent b1b0ab3 commit 8333ddf

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,11 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
773773
private boolean maybeSampleForApiSecurity(
774774
AppSecRequestContext ctx, IGSpanInfo spanInfo, Map<String, Object> tags) {
775775
log.debug("Checking API Security for end of request handler on span: {}", spanInfo.getSpanId());
776-
// API Security sampling requires http.route tag.
776+
// API Security sampling requires http.route tag. If it is not present, we set empty string to
777+
// avoid filtering all requests when http route is not implemented for some frameworks.
777778
final Object route = tags.get(Tags.HTTP_ROUTE);
778-
if (route != null) {
779-
ctx.setRoute(route.toString());
780-
}
779+
String routeStr = route != null ? route.toString() : "";
780+
ctx.setRoute(routeStr);
781781
return requestSampler.preSampleRequest(ctx);
782782
}
783783

dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/gateway/GatewayBridgeSpecification.groovy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,24 @@ class GatewayBridgeSpecification extends DDSpecification {
11851185
0 * traceSegment.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTraceSource.ASM)
11861186
}
11871187
1188+
void 'test api security sampling - No http route'() {
1189+
given:
1190+
AppSecRequestContext mockAppSecCtx = Mock(AppSecRequestContext)
1191+
RequestContext mockCtx = Stub(RequestContext) {
1192+
getData(RequestContextSlot.APPSEC) >> mockAppSecCtx
1193+
getTraceSegment() >> traceSegment
1194+
}
1195+
IGSpanInfo spanInfo = Mock(AgentSpan)
1196+
when:
1197+
def flow = requestEndedCB.apply(mockCtx, spanInfo)
1198+
then:
1199+
1 * mockAppSecCtx.transferCollectedEvents() >> []
1200+
1 * spanInfo.getTags() >> ['http.route': null]
1201+
1 * requestSampler.preSampleRequest(_) >> true
1202+
0 * traceSegment.setTagTop(Tags.ASM_KEEP, true)
1203+
0 * traceSegment.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTraceSource.ASM)
1204+
}
1205+
11881206
void 'test api security sampling - trace excluded'() {
11891207
given:
11901208
AppSecRequestContext mockAppSecCtx = Mock(AppSecRequestContext)

0 commit comments

Comments
 (0)