Skip to content

Commit 4d1ba30

Browse files
committed
self review
1 parent 7d7782a commit 4d1ba30

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

dd-java-agent/appsec/src/main/java/com/datadog/appsec/api/security/ApiSecuritySamplerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ public boolean preSampleRequest(final @Nonnull AppSecRequestContext ctx) {
6666
}
6767
long hash = computeApiHash(route, method, statusCode);
6868
ctx.setApiSecurityEndpointHash(hash);
69-
7069
if (!isApiAccessExpired(hash)) {
7170
return false;
7271
}
73-
7472
if (counter.tryAcquire()) {
7573
log.debug("API security sampling is required for this request (presampled)");
7674
ctx.setKeepOpenForApiSecurityPostProcessing(true);
@@ -95,6 +93,7 @@ public boolean sampleRequest(AppSecRequestContext ctx) {
9593
}
9694
final Long hash = ctx.getApiSecurityEndpointHash();
9795
if (hash == null) {
96+
// This should never happen, it should have been short-circuited before.
9897
return false;
9998
}
10099
return true;

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -837,19 +837,15 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
837837
Map<String, Object> tags = spanInfo.getTags();
838838

839839
boolean sampledForApiSec = maybeSampleForApiSecurity(ctx, spanInfo, tags);
840-
boolean apmTracingEnabled = Config.get().isApmTracingEnabled();
841840

842841
if (!sampledForApiSec) {
843842
ctx.closeWafContext();
844843
}
845844

846845
// AppSec report metric and events for web span only
847846
if (traceSeg != null) {
848-
// Set API Security sampling tags if needed
849-
if (sampledForApiSec && !apmTracingEnabled) {
847+
if (sampledForApiSec && !Config.get().isApmTracingEnabled()) {
850848
traceSeg.setTagTop(Tags.ASM_KEEP, true);
851-
// Must set _dd.p.ts locally so TraceCollector respects force-keep in standalone mode
852-
// (TraceCollector.java lines 67-74 ignore force-keep without _dd.p.ts when APM disabled)
853849
traceSeg.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTraceSource.ASM);
854850
}
855851

@@ -869,8 +865,7 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
869865

870866
// If detected any events - mark span at appsec.event
871867
if (!collectedEvents.isEmpty()) {
872-
boolean manuallyKept = ctx.isManuallyKept();
873-
if (manuallyKept) {
868+
if (ctx.isManuallyKept()) {
874869
// Set asm keep in case that root span was not available when events are detected
875870
traceSeg.setTagTop(Tags.ASM_KEEP, true);
876871
traceSeg.setTagTop(Tags.PROPAGATED_TRACE_SOURCE, ProductTraceSource.ASM);
@@ -942,14 +937,11 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
942937
private boolean maybeSampleForApiSecurity(
943938
AppSecRequestContext ctx, IGSpanInfo spanInfo, Map<String, Object> tags) {
944939
log.debug("Checking API Security for end of request handler on span: {}", spanInfo.getSpanId());
945-
946940
// API Security sampling requires http.route tag.
947941
final Object route = tags.get(Tags.HTTP_ROUTE);
948-
949942
if (route != null) {
950943
ctx.setRoute(route.toString());
951944
}
952-
953945
ApiSecuritySampler requestSampler = requestSamplerSupplier.get();
954946
return requestSampler.preSampleRequest(ctx);
955947
}

0 commit comments

Comments
 (0)