@@ -836,8 +836,25 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
836836 TraceSegment traceSeg = ctx_ .getTraceSegment ();
837837 Map <String , Object > tags = spanInfo .getTags ();
838838
839- if (maybeSampleForApiSecurity (ctx , spanInfo , tags )) {
840- if (!Config .get ().isApmTracingEnabled ()) {
839+ // Log upstream propagated tags
840+ Object upstreamPropagatedTs = tags .get (Tags .PROPAGATED_TRACE_SOURCE );
841+ log .info (
842+ "[APPSEC-57815] Request ended - spanId={}, upstream _dd.p.ts={}" ,
843+ spanInfo .getSpanId (),
844+ upstreamPropagatedTs );
845+
846+ boolean sampledForApiSec = maybeSampleForApiSecurity (ctx , spanInfo , tags );
847+ boolean apmTracingEnabled = Config .get ().isApmTracingEnabled ();
848+
849+ log .info (
850+ "[APPSEC-57815] sampledForApiSec={}, apmTracingEnabled={}" ,
851+ sampledForApiSec ,
852+ apmTracingEnabled );
853+
854+ if (sampledForApiSec ) {
855+ if (!apmTracingEnabled ) {
856+ log .info (
857+ "[APPSEC-57815] Setting ASM_KEEP=true (API Security sampled, APM tracing disabled)" );
841858 traceSeg .setTagTop (Tags .ASM_KEEP , true );
842859 // Note: _dd.p.ts (PROPAGATED_TRACE_SOURCE) is only set when there are actual AppSec events
843860 // (see lines below where collectedEvents is checked), not just for API Security sampling
@@ -853,6 +870,8 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
853870
854871 Collection <AppSecEvent > collectedEvents = ctx .transferCollectedEvents ();
855872
873+ log .info ("[APPSEC-57815] Collected {} AppSec events" , collectedEvents .size ());
874+
856875 for (TraceSegmentPostProcessor pp : this .traceSegmentPostProcessors ) {
857876 pp .processTraceSegment (traceSeg , ctx , collectedEvents );
858877 }
@@ -864,8 +883,12 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
864883
865884 // If detected any events - mark span at appsec.event
866885 if (!collectedEvents .isEmpty ()) {
867- if (ctx .isManuallyKept ()) {
886+ boolean manuallyKept = ctx .isManuallyKept ();
887+ log .info ("[APPSEC-57815] AppSec events detected - manuallyKept={}" , manuallyKept );
888+ if (manuallyKept ) {
868889 // Set asm keep in case that root span was not available when events are detected
890+ log .info (
891+ "[APPSEC-57815] Setting ASM_KEEP=true and _dd.p.ts=ASM (AppSec events + manually kept)" );
869892 traceSeg .setTagTop (Tags .ASM_KEEP , true );
870893 traceSeg .setTagTop (Tags .PROPAGATED_TRACE_SOURCE , ProductTraceSource .ASM );
871894 }
@@ -929,6 +952,14 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
929952 );
930953 }
931954
955+ // Log final state of propagation tags
956+ Object finalPropagatedTs = tags .get (Tags .PROPAGATED_TRACE_SOURCE );
957+ Object finalAsmKeep = tags .get (Tags .ASM_KEEP );
958+ log .info (
959+ "[APPSEC-57815] Request ended - final state: _dd.p.ts={}, _dd.appsec.keep={}" ,
960+ finalPropagatedTs ,
961+ finalAsmKeep );
962+
932963 ctx .close ();
933964 return NoopFlow .INSTANCE ;
934965 }
@@ -942,7 +973,10 @@ private boolean maybeSampleForApiSecurity(
942973 ctx .setRoute (route .toString ());
943974 }
944975 ApiSecuritySampler requestSampler = requestSamplerSupplier .get ();
945- return requestSampler .preSampleRequest (ctx );
976+ boolean sampled = requestSampler .preSampleRequest (ctx );
977+ log .info (
978+ "[APPSEC-57815] API Security sampling decision - route={}, sampled={}" , route , sampled );
979+ return sampled ;
946980 }
947981
948982 private Flow <Void > onRequestHeadersDone (RequestContext ctx_ ) {
0 commit comments