@@ -43,7 +43,7 @@ use std::pin::Pin;
4343use std:: sync:: Arc ;
4444use std:: time:: Instant ;
4545use tokio:: task:: JoinSet ;
46- use tracing:: { error, warn} ;
46+ use tracing:: { error, instrument , warn} ;
4747
4848use crate :: event:: { DEFAULT_TIMESTAMP_KEY , commit_schema} ;
4949use crate :: metrics:: { QUERY_EXECUTE_TIME , increment_query_calls_by_date} ;
@@ -115,6 +115,7 @@ pub async fn get_records_and_fields(
115115 Ok ( ( Some ( records) , Some ( fields) ) )
116116}
117117
118+ #[ instrument( name = "POST /query" , skip_all, fields( http. request. method = "POST" , http. route = "/query" ) ) ]
118119pub async fn query ( req : HttpRequest , query_request : Query ) -> Result < HttpResponse , QueryError > {
119120 let mut session_state = QUERY_SESSION . get_ctx ( ) . state ( ) ;
120121 let time_range =
@@ -179,6 +180,7 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons
179180///
180181/// # Returns
181182/// - `HttpResponse` with the count result as JSON, including fields if requested.
183+ #[ instrument( name = "handle_count_query" , skip_all, fields( db. collection. name = %table_name) ) ]
182184async fn handle_count_query (
183185 query_request : & Query ,
184186 table_name : & str ,
@@ -230,6 +232,7 @@ async fn handle_count_query(
230232///
231233/// # Returns
232234/// - `HttpResponse` with the full query result as a JSON object.
235+ #[ instrument( name = "handle_non_streaming_query" , skip_all, fields( db. collection. name) ) ]
233236async fn handle_non_streaming_query (
234237 query : LogicalQuery ,
235238 table_name : Vec < String > ,
@@ -238,6 +241,7 @@ async fn handle_non_streaming_query(
238241 tenant_id : & Option < String > ,
239242) -> Result < HttpResponse , QueryError > {
240243 let first_table_name = table_name[ 0 ] . clone ( ) ;
244+ tracing:: Span :: current ( ) . record ( "db.collection.name" , & first_table_name. as_str ( ) ) ;
241245 let ( records, fields) = execute ( query, query_request. streaming , tenant_id) . await ?;
242246 let records = match records {
243247 Either :: Left ( rbs) => rbs,
@@ -283,6 +287,7 @@ async fn handle_non_streaming_query(
283287///
284288/// # Returns
285289/// - `HttpResponse` streaming the query results as NDJSON, optionally prefixed with the fields array.
290+ #[ instrument( name = "handle_streaming_query" , skip_all, fields( db. collection. name) ) ]
286291async fn handle_streaming_query (
287292 query : LogicalQuery ,
288293 table_name : Vec < String > ,
@@ -291,6 +296,7 @@ async fn handle_streaming_query(
291296 tenant_id : & Option < String > ,
292297) -> Result < HttpResponse , QueryError > {
293298 let first_table_name = table_name[ 0 ] . clone ( ) ;
299+ tracing:: Span :: current ( ) . record ( "db.collection.name" , & first_table_name. as_str ( ) ) ;
294300 let ( records_stream, fields) = execute ( query, query_request. streaming , tenant_id) . await ?;
295301 let records_stream = match records_stream {
296302 Either :: Left ( _) => {
@@ -516,6 +522,7 @@ pub async fn update_schema_when_distributed(
516522/// Create streams for querier if they do not exist
517523/// get list of streams from memory and storage
518524/// create streams for memory from storage if they do not exist
525+ #[ instrument( name = "create_streams_for_distributed" , skip_all) ]
519526pub async fn create_streams_for_distributed (
520527 streams : Vec < String > ,
521528 tenant_id : & Option < String > ,
@@ -526,17 +533,21 @@ pub async fn create_streams_for_distributed(
526533 let mut join_set = JoinSet :: new ( ) ;
527534 for stream_name in streams {
528535 let id = tenant_id. to_owned ( ) ;
529- join_set. spawn ( async move {
530- let result = PARSEABLE
531- . create_stream_and_schema_from_storage ( & stream_name, & id)
532- . await ;
533-
534- if let Err ( e) = & result {
535- warn ! ( "Failed to create stream '{}': {}" , stream_name, e) ;
536- }
537-
538- ( stream_name, result)
539- } ) ;
536+ let span = tracing:: Span :: current ( ) ;
537+ join_set. spawn ( tracing:: Instrument :: instrument (
538+ async move {
539+ let result = PARSEABLE
540+ . create_stream_and_schema_from_storage ( & stream_name, & id)
541+ . await ;
542+
543+ if let Err ( e) = & result {
544+ warn ! ( "Failed to create stream '{}': {}" , stream_name, e) ;
545+ }
546+
547+ ( stream_name, result)
548+ } ,
549+ span,
550+ ) ) ;
540551 }
541552
542553 while let Some ( result) = join_set. join_next ( ) . await {
@@ -579,6 +590,7 @@ impl FromRequest for Query {
579590 }
580591}
581592
593+ #[ instrument( name = "into_query" , skip_all, fields( db. query. text = %query. query) ) ]
582594pub async fn into_query (
583595 query : & Query ,
584596 session_state : & SessionState ,
0 commit comments