@@ -861,28 +861,17 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
861861 if (traceSeg != null ) {
862862 // Set API Security sampling tags if needed
863863 if (sampledForApiSec && !apmTracingEnabled ) {
864- log .info (
865- "[APPSEC-57815] Setting ASM_KEEP=true (API Security sampled, APM tracing disabled)" );
866864 traceSeg .setTagTop (Tags .ASM_KEEP , true );
867865 // Must set _dd.p.ts locally so TraceCollector respects force-keep in standalone mode
868866 // (TraceCollector.java lines 67-74 ignore force-keep without _dd.p.ts when APM disabled)
869867 traceSeg .setTagTop (Tags .PROPAGATED_TRACE_SOURCE , ProductTraceSource .ASM );
870- // Verify the tag was set
871- Object asmKeepAfterSet = traceSeg .getTagTop (Tags .ASM_KEEP );
872- Object propagatedTsAfterSet = traceSeg .getTagTop (Tags .PROPAGATED_TRACE_SOURCE );
873- log .info (
874- "[APPSEC-57815] After setTagTop - ASM_KEEP: {}, _dd.p.ts: {}" ,
875- asmKeepAfterSet ,
876- propagatedTsAfterSet );
877868 }
878869
879870 traceSeg .setTagTop ("_dd.appsec.enabled" , 1 );
880871 traceSeg .setTagTop ("_dd.runtime_family" , "jvm" );
881872
882873 Collection <AppSecEvent > collectedEvents = ctx .transferCollectedEvents ();
883874
884- log .info ("[APPSEC-57815] Collected {} AppSec events" , collectedEvents .size ());
885-
886875 for (TraceSegmentPostProcessor pp : this .traceSegmentPostProcessors ) {
887876 pp .processTraceSegment (traceSeg , ctx , collectedEvents );
888877 }
@@ -895,11 +884,8 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
895884 // If detected any events - mark span at appsec.event
896885 if (!collectedEvents .isEmpty ()) {
897886 boolean manuallyKept = ctx .isManuallyKept ();
898- log .info ("[APPSEC-57815] AppSec events detected - manuallyKept={}" , manuallyKept );
899887 if (manuallyKept ) {
900888 // Set asm keep in case that root span was not available when events are detected
901- log .info (
902- "[APPSEC-57815] Setting ASM_KEEP=true and _dd.p.ts=ASM (AppSec events + manually kept)" );
903889 traceSeg .setTagTop (Tags .ASM_KEEP , true );
904890 traceSeg .setTagTop (Tags .PROPAGATED_TRACE_SOURCE , ProductTraceSource .ASM );
905891 }
@@ -963,29 +949,32 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
963949 );
964950 }
965951
966- // Log final state of propagation tags from TraceSegment (not from spanInfo.getTags() which is
967- // immutable)
968- Object finalPropagatedTs = traceSeg .getTagTop (Tags .PROPAGATED_TRACE_SOURCE );
969- Object finalAsmKeep = traceSeg .getTagTop (Tags .ASM_KEEP );
970- log .info (
971- "[APPSEC-57815] Request ended - final state from TraceSegment: _dd.p.ts={}, _dd.appsec.keep={}" ,
972- finalPropagatedTs ,
973- finalAsmKeep );
974-
975952 ctx .close ();
976953 return NoopFlow .INSTANCE ;
977954 }
978955
979956 private boolean maybeSampleForApiSecurity (
980957 AppSecRequestContext ctx , IGSpanInfo spanInfo , Map <String , Object > tags ) {
981958 log .debug ("Checking API Security for end of request handler on span: {}" , spanInfo .getSpanId ());
959+
982960 // API Security sampling requires http.route tag.
983961 final Object route = tags .get (Tags .HTTP_ROUTE );
962+ final String existingRoute = ctx .getRoute ();
963+
964+ log .info (
965+ "[APPSEC-57815] maybeSampleForApiSecurity called - spanId={}, route from tags={}, existingRoute={}, ctx.hashCode={}" ,
966+ spanInfo .getSpanId (),
967+ route ,
968+ existingRoute ,
969+ System .identityHashCode (ctx ));
970+
984971 if (route != null ) {
985972 ctx .setRoute (route .toString ());
986973 }
974+
987975 ApiSecuritySampler requestSampler = requestSamplerSupplier .get ();
988976 boolean sampled = requestSampler .preSampleRequest (ctx );
977+
989978 log .info (
990979 "[APPSEC-57815] API Security sampling decision - route={}, sampled={}" , route , sampled );
991980 return sampled ;
0 commit comments