@@ -847,12 +847,20 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
847847 boolean apmTracingEnabled = Config .get ().isApmTracingEnabled ();
848848
849849 log .info (
850- "[APPSEC-57815] sampledForApiSec={}, apmTracingEnabled={}" ,
850+ "[APPSEC-57815] sampledForApiSec={}, apmTracingEnabled={}, traceSeg={}, isNoOp={} " ,
851851 sampledForApiSec ,
852- apmTracingEnabled );
852+ apmTracingEnabled ,
853+ traceSeg ,
854+ traceSeg == TraceSegment .NoOp .INSTANCE );
855+
856+ if (!sampledForApiSec ) {
857+ ctx .closeWafContext ();
858+ }
853859
854- if (sampledForApiSec ) {
855- if (!apmTracingEnabled ) {
860+ // AppSec report metric and events for web span only
861+ if (traceSeg != null ) {
862+ // Set API Security sampling tags if needed
863+ if (sampledForApiSec && !apmTracingEnabled ) {
856864 log .info (
857865 "[APPSEC-57815] Setting ASM_KEEP=true (API Security sampled, APM tracing disabled)" );
858866 traceSeg .setTagTop (Tags .ASM_KEEP , true );
@@ -861,14 +869,13 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
861869 traceSeg .setTagTop (Tags .PROPAGATED_TRACE_SOURCE , ProductTraceSource .ASM );
862870 // Verify the tag was set
863871 Object asmKeepAfterSet = traceSeg .getTagTop (Tags .ASM_KEEP );
864- log .info ("[APPSEC-57815] ASM_KEEP after setTagTop: {}" , asmKeepAfterSet );
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 );
865877 }
866- } else {
867- ctx .closeWafContext ();
868- }
869878
870- // AppSec report metric and events for web span only
871- if (traceSeg != null ) {
872879 traceSeg .setTagTop ("_dd.appsec.enabled" , 1 );
873880 traceSeg .setTagTop ("_dd.runtime_family" , "jvm" );
874881
0 commit comments