@@ -163,7 +163,7 @@ struct SpanBuilderUpdates {
163163}
164164
165165impl SpanBuilderUpdates {
166- fn update ( self , span_builder : & mut SpanBuilder ) {
166+ fn update ( self , span_builder : & mut SpanBuilder , s : & mut Status ) {
167167 let Self {
168168 name,
169169 span_kind,
@@ -178,7 +178,7 @@ impl SpanBuilderUpdates {
178178 span_builder. span_kind = Some ( span_kind) ;
179179 }
180180 if let Some ( status) = status {
181- span_builder . status = status;
181+ * s = status;
182182 }
183183 if let Some ( attributes) = attributes {
184184 if let Some ( builder_attributes) = & mut span_builder. attributes {
@@ -974,8 +974,16 @@ where
974974 fn start_cx ( & self , otel_data : & mut OtelData ) {
975975 if let OtelDataState :: Context { .. } = & otel_data. state {
976976 // If the context is already started, we do nothing.
977- } else if let OtelDataState :: Builder { builder, parent_cx } = take ( & mut otel_data. state ) {
978- let span = builder. start_with_context ( & self . tracer , & parent_cx) ;
977+ } else if let OtelDataState :: Builder {
978+ builder,
979+ parent_cx,
980+ status,
981+ } = take ( & mut otel_data. state )
982+ {
983+ let mut span = builder. start_with_context ( & self . tracer , & parent_cx) ;
984+ if status != Status :: Unset {
985+ span. set_status ( status) ;
986+ }
979987 let current_cx = parent_cx. with_span ( span) ;
980988 otel_data. state = OtelDataState :: Context { current_cx } ;
981989 }
@@ -1077,9 +1085,14 @@ where
10771085 sem_conv_config : self . sem_conv_config ,
10781086 } ) ;
10791087
1080- updates. update ( & mut builder) ;
1088+ let mut status = Status :: Unset ;
1089+ updates. update ( & mut builder, & mut status) ;
10811090 extensions. insert ( OtelData {
1082- state : OtelDataState :: Builder { builder, parent_cx } ,
1091+ state : OtelDataState :: Builder {
1092+ builder,
1093+ parent_cx,
1094+ status,
1095+ } ,
10831096 end_time : None ,
10841097 } ) ;
10851098 }
@@ -1153,9 +1166,11 @@ where
11531166 let mut extensions = span. extensions_mut ( ) ;
11541167 if let Some ( otel_data) = extensions. get_mut :: < OtelData > ( ) {
11551168 match & mut otel_data. state {
1156- OtelDataState :: Builder { builder, .. } => {
1169+ OtelDataState :: Builder {
1170+ builder, status, ..
1171+ } => {
11571172 // If the builder is present, then update it.
1158- updates. update ( builder) ;
1173+ updates. update ( builder, status ) ;
11591174 }
11601175 OtelDataState :: Context { current_cx, .. } => {
11611176 // If the Context has been created, then update the span.
@@ -1298,14 +1313,16 @@ where
12981313 }
12991314
13001315 match & mut otel_data. state {
1301- OtelDataState :: Builder { builder, .. } => {
1302- if builder. status == otel:: Status :: Unset
1316+ OtelDataState :: Builder {
1317+ builder, status, ..
1318+ } => {
1319+ if * status == otel:: Status :: Unset
13031320 && * meta. level ( ) == tracing_core:: Level :: ERROR
13041321 {
1305- builder . status = otel:: Status :: error ( "" ) ;
1322+ * status = otel:: Status :: error ( "" ) ;
13061323 }
13071324 if let Some ( builder_updates) = builder_updates {
1308- builder_updates. update ( builder) ;
1325+ builder_updates. update ( builder, status ) ;
13091326 }
13101327 if let Some ( ref mut events) = builder. events {
13111328 events. push ( otel_event) ;
@@ -1358,12 +1375,19 @@ where
13581375 } ) ;
13591376
13601377 match state {
1361- OtelDataState :: Builder { builder, parent_cx } => {
1378+ OtelDataState :: Builder {
1379+ builder,
1380+ parent_cx,
1381+ status,
1382+ } => {
13621383 // Don't create the context here just to get a SpanRef since it's costly
13631384 let mut span = builder. start_with_context ( & self . tracer , & parent_cx) ;
13641385 if let Some ( timings) = timings {
13651386 span. set_attributes ( timings)
13661387 } ;
1388+ if status != Status :: Unset {
1389+ span. set_status ( status) ;
1390+ }
13671391 if let Some ( end_time) = end_time {
13681392 span. end_with_timestamp ( end_time) ;
13691393 } else {
0 commit comments