Skip to content

Commit e24b368

Browse files
committed
http route fallback
1 parent be7f9d3 commit e24b368

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
@@ -820,11 +820,11 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
820820
private boolean maybeSampleForApiSecurity(
821821
AppSecRequestContext ctx, IGSpanInfo spanInfo, Map<String, Object> tags) {
822822
log.debug("Checking API Security for end of request handler on span: {}", spanInfo.getSpanId());
823-
// API Security sampling requires http.route tag.
823+
// API Security sampling requires http.route tag. If it is not present, we set empty string to
824+
// avoid filtering all requests when http route is not implemented for some frameworks.
824825
final Object route = tags.get(Tags.HTTP_ROUTE);
825-
if (route != null) {
826-
ctx.setRoute(route.toString());
827-
}
826+
String routeStr = route != null ? route.toString() : "";
827+
ctx.setRoute(routeStr);
828828
ApiSecuritySampler requestSampler = requestSamplerSupplier.get();
829829
return requestSampler.preSampleRequest(ctx);
830830
}

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
@@ -1202,6 +1202,24 @@ class GatewayBridgeSpecification extends DDSpecification {
12021202
0 * traceSegment.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTraceSource.ASM)
12031203
}
12041204
1205+
void 'test api security sampling - No http route'() {
1206+
given:
1207+
AppSecRequestContext mockAppSecCtx = Mock(AppSecRequestContext)
1208+
RequestContext mockCtx = Stub(RequestContext) {
1209+
getData(RequestContextSlot.APPSEC) >> mockAppSecCtx
1210+
getTraceSegment() >> traceSegment
1211+
}
1212+
IGSpanInfo spanInfo = Mock(AgentSpan)
1213+
when:
1214+
def flow = requestEndedCB.apply(mockCtx, spanInfo)
1215+
then:
1216+
1 * mockAppSecCtx.transferCollectedEvents() >> []
1217+
1 * spanInfo.getTags() >> ['http.route': null]
1218+
1 * requestSampler.preSampleRequest(_) >> true
1219+
0 * traceSegment.setTagTop(Tags.ASM_KEEP, true)
1220+
0 * traceSegment.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTraceSource.ASM)
1221+
}
1222+
12051223
void 'test api security sampling - trace excluded'() {
12061224
given:
12071225
AppSecRequestContext mockAppSecCtx = Mock(AppSecRequestContext)

0 commit comments

Comments
 (0)