@@ -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 {
@@ -973,8 +973,16 @@ where
973973 fn start_cx ( & self , otel_data : & mut OtelData ) {
974974 if let OtelDataState :: Context { .. } = & otel_data. state {
975975 // If the context is already started, we do nothing.
976- } else if let OtelDataState :: Builder { builder, parent_cx } = take ( & mut otel_data. state ) {
977- let span = builder. start_with_context ( & self . tracer , & parent_cx) ;
976+ } else if let OtelDataState :: Builder {
977+ builder,
978+ parent_cx,
979+ status,
980+ } = take ( & mut otel_data. state )
981+ {
982+ let mut span = builder. start_with_context ( & self . tracer , & parent_cx) ;
983+ if status != Status :: Unset {
984+ span. set_status ( status) ;
985+ }
978986 let current_cx = parent_cx. with_span ( span) ;
979987 otel_data. state = OtelDataState :: Context { current_cx } ;
980988 }
@@ -1076,9 +1084,14 @@ where
10761084 sem_conv_config : self . sem_conv_config ,
10771085 } ) ;
10781086
1079- updates. update ( & mut builder) ;
1087+ let mut status = Status :: Unset ;
1088+ updates. update ( & mut builder, & mut status) ;
10801089 extensions. insert ( OtelData {
1081- state : OtelDataState :: Builder { builder, parent_cx } ,
1090+ state : OtelDataState :: Builder {
1091+ builder,
1092+ parent_cx,
1093+ status,
1094+ } ,
10821095 end_time : None ,
10831096 } ) ;
10841097 }
@@ -1152,9 +1165,11 @@ where
11521165 let mut extensions = span. extensions_mut ( ) ;
11531166 if let Some ( otel_data) = extensions. get_mut :: < OtelData > ( ) {
11541167 match & mut otel_data. state {
1155- OtelDataState :: Builder { builder, .. } => {
1168+ OtelDataState :: Builder {
1169+ builder, status, ..
1170+ } => {
11561171 // If the builder is present, then update it.
1157- updates. update ( builder) ;
1172+ updates. update ( builder, status ) ;
11581173 }
11591174 OtelDataState :: Context { current_cx, .. } => {
11601175 // If the Context has been created, then update the span.
@@ -1297,14 +1312,16 @@ where
12971312 }
12981313
12991314 match & mut otel_data. state {
1300- OtelDataState :: Builder { builder, .. } => {
1301- if builder. status == otel:: Status :: Unset
1315+ OtelDataState :: Builder {
1316+ builder, status, ..
1317+ } => {
1318+ if * status == otel:: Status :: Unset
13021319 && * meta. level ( ) == tracing_core:: Level :: ERROR
13031320 {
1304- builder . status = otel:: Status :: error ( "" ) ;
1321+ * status = otel:: Status :: error ( "" ) ;
13051322 }
13061323 if let Some ( builder_updates) = builder_updates {
1307- builder_updates. update ( builder) ;
1324+ builder_updates. update ( builder, status ) ;
13081325 }
13091326 if let Some ( ref mut events) = builder. events {
13101327 events. push ( otel_event) ;
@@ -1357,12 +1374,17 @@ where
13571374 } ) ;
13581375
13591376 match state {
1360- OtelDataState :: Builder { builder, parent_cx } => {
1377+ OtelDataState :: Builder {
1378+ builder,
1379+ parent_cx,
1380+ status,
1381+ } => {
13611382 // Don't create the context here just to get a SpanRef since it's costly
13621383 let mut span = builder. start_with_context ( & self . tracer , & parent_cx) ;
13631384 if let Some ( timings) = timings {
13641385 span. set_attributes ( timings)
13651386 } ;
1387+ span. set_status ( status) ;
13661388 if let Some ( end_time) = end_time {
13671389 span. end_with_timestamp ( end_time) ;
13681390 } else {
0 commit comments