@@ -31,30 +31,45 @@ public AppSecSpanPostProcessor(ApiSecuritySampler sampler, EventProducerService
3131
3232 @ Override
3333 public void process (@ Nonnull AgentSpan span , @ Nonnull BooleanSupplier timeoutCheck ) {
34+ long timestamp = System .currentTimeMillis ();
35+ String traceId = span .getTraceId () != null ? span .getTraceId ().toString () : "null" ;
36+ String spanId = String .valueOf (span .getSpanId ());
37+
3438 final RequestContext ctx_ = span .getRequestContext ();
3539 if (ctx_ == null ) {
40+ logProcessingDecision (timestamp , traceId , spanId , false , "no request context" , "start" );
3641 return ;
3742 }
3843 final AppSecRequestContext ctx = ctx_ .getData (RequestContextSlot .APPSEC );
3944 if (ctx == null ) {
45+ logProcessingDecision (timestamp , traceId , spanId , false , "no appsec context" , "start" );
4046 return ;
4147 }
4248
4349 if (!ctx .isKeepOpenForApiSecurityPostProcessing ()) {
50+ logProcessingDecision (
51+ timestamp , traceId , spanId , false , "not marked for post-processing" , "start" );
4452 return ;
4553 }
4654
4755 try {
4856 if (timeoutCheck .getAsBoolean ()) {
4957 log .debug ("Timeout detected, skipping API security post-processing" );
58+ logProcessingDecision (
59+ timestamp , traceId , spanId , false , "timeout detected" , "pre-sampling" );
5060 return ;
5161 }
5262 if (!sampler .sampleRequest (ctx )) {
5363 log .debug ("Request not sampled, skipping API security post-processing" );
64+ logProcessingDecision (
65+ timestamp , traceId , spanId , false , "request not sampled" , "post-sampling" );
5466 return ;
5567 }
5668 log .debug ("Request sampled, processing API security post-processing" );
69+ logProcessingDecision (
70+ timestamp , traceId , spanId , true , "sampled, extracting schemas" , "extracting" );
5771 extractSchemas (ctx , ctx_ .getTraceSegment ());
72+ logProcessingDecision (timestamp , traceId , spanId , true , "extraction completed" , "completed" );
5873 } finally {
5974 ctx .setKeepOpenForApiSecurityPostProcessing (false );
6075 try {
@@ -67,6 +82,7 @@ public void process(@Nonnull AgentSpan span, @Nonnull BooleanSupplier timeoutChe
6782 log .debug ("Error closing AppSecRequestContext" , e );
6883 }
6984 sampler .releaseOne ();
85+ logProcessingDecision (timestamp , traceId , spanId , false , "cleanup completed" , "cleanup" );
7086 }
7187 }
7288
@@ -89,4 +105,21 @@ private void extractSchemas(final AppSecRequestContext ctx, final TraceSegment t
89105 log .debug ("Subscriber info expired" , e );
90106 }
91107 }
108+
109+ private void logProcessingDecision (
110+ long timestamp ,
111+ String traceId ,
112+ String spanId ,
113+ boolean processed ,
114+ String reason ,
115+ String stage ) {
116+ log .info (
117+ "[APPSEC_SPAN_POST_PROCESSING] timestamp={}, traceId={}, spanId={}, processed={}, reason={}, stage={}" ,
118+ timestamp ,
119+ traceId ,
120+ spanId ,
121+ processed ,
122+ reason ,
123+ stage );
124+ }
92125}
0 commit comments