@@ -10,6 +10,9 @@ use hyper::service::service_fn;
1010use hyper:: { Request , Response , StatusCode } ;
1111use tokio:: net:: TcpListener ;
1212
13+ use opentelemetry:: trace:: TraceContextExt ;
14+ use tracing_opentelemetry:: OpenTelemetrySpanExt ;
15+
1316use super :: diagnostic_store:: DiagnosticStore ;
1417
1518const IDLE_TIMEOUT : Duration = Duration :: from_secs ( 30 ) ;
@@ -71,12 +74,19 @@ async fn handle_report(
7174 } ;
7275
7376 let message = String :: from_utf8_lossy ( & body_bytes) . into_owned ( ) ;
74- let _span = tracing:: info_span!( parent: & root_span, "lsp.llm_report" , message = %message) . entered ( ) ;
77+ let span = tracing:: info_span!( parent: & root_span, "lsp.llm_report" , message = %message) ;
78+ let _entered = span. enter ( ) ;
79+
80+ // Extract the OTEL span ID so the caller can look it up in the trace viewer
81+ let otel_context = span. context ( ) ;
82+ let span_ref = otel_context. span ( ) ;
83+ let span_id = span_ref. span_context ( ) . span_id ( ) . to_string ( ) ;
7584
85+ let body = format ! ( r#"{{"status": "recorded", "span_id": "{span_id}"}}"# ) ;
7686 Response :: builder ( )
7787 . status ( StatusCode :: OK )
7888 . header ( "Content-Type" , "application/json" )
79- . body ( Full :: new ( Bytes :: from ( r#"{"status": "recorded"}"# ) ) )
89+ . body ( Full :: new ( Bytes :: from ( body ) ) )
8090 . unwrap ( )
8191}
8292
0 commit comments