@@ -3,8 +3,6 @@ use crate::bson::RawDocumentBuf;
33use crate :: bson:: { doc, RawBsonRef , RawDocument , Timestamp } ;
44#[ cfg( feature = "in-use-encryption" ) ]
55use futures_core:: future:: BoxFuture ;
6- #[ cfg( feature = "opentelemetry" ) ]
7- use opentelemetry:: context:: FutureExt ;
86use serde:: de:: DeserializeOwned ;
97use std:: sync:: LazyLock ;
108
@@ -16,8 +14,6 @@ use std::{
1614} ;
1715
1816use super :: { options:: ServerAddress , session:: TransactionState , Client , ClientSession } ;
19- #[ cfg( not( feature = "opentelemetry" ) ) ]
20- use crate :: otel:: OtelFutureStub as _;
2117use crate :: {
2218 bson:: Document ,
2319 change_stream:: {
@@ -105,19 +101,30 @@ impl Client {
105101 . map ( |details| details. output )
106102 }
107103
104+ #[ cfg( not( feature = "opentelemetry" ) ) ]
108105 async fn execute_operation_with_details < T : Operation > (
109106 & self ,
110107 op : & mut T ,
111108 session : impl Into < Option < & mut ClientSession > > ,
112109 ) -> Result < ExecutionDetails < T > > {
110+ self . execute_operation_with_details_inner ( op, session. into ( ) )
111+ . await
112+ }
113+
114+ #[ cfg( feature = "opentelemetry" ) ]
115+ async fn execute_operation_with_details < T : Operation > (
116+ & self ,
117+ op : & mut T ,
118+ session : impl Into < Option < & mut ClientSession > > ,
119+ ) -> Result < ExecutionDetails < T > > {
120+ use crate :: otel:: FutureExt as _;
121+
113122 let session = session. into ( ) ;
114- #[ cfg( feature = "opentelemetry" ) ]
115123 let span = self . start_operation_span ( op, session. as_deref ( ) ) ;
116- let inner = self . execute_operation_with_details_inner ( op, session) ;
117- #[ cfg( feature = "opentelemetry" ) ]
118- let inner = inner. with_context ( span. context . clone ( ) ) ;
119- let result = inner. await ;
120- #[ cfg( feature = "opentelemetry" ) ]
124+ let result = self
125+ . execute_operation_with_details_inner ( op, session)
126+ . with_span ( & span)
127+ . await ;
121128 span. record_error ( & result) ;
122129
123130 result
@@ -176,13 +183,7 @@ impl Client {
176183 }
177184 }
178185
179- Box :: pin ( async {
180- self . execute_operation_with_retry ( op, session)
181- . with_current_context ( )
182- . await
183- } )
184- . with_current_context ( )
185- . await
186+ Box :: pin ( async { self . execute_operation_with_retry ( op, session) . await } ) . await
186187 }
187188
188189 /// Execute the given operation, returning the cursor created by the operation.
@@ -436,7 +437,6 @@ impl Client {
436437 retryability,
437438 effective_criteria,
438439 )
439- . with_current_context ( )
440440 . await
441441 {
442442 Ok ( output) => ExecutionDetails {
0 commit comments