@@ -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,14 @@ 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+ span. set_status ( status) ;
978984 let current_cx = parent_cx. with_span ( span) ;
979985 otel_data. state = OtelDataState :: Context { current_cx } ;
980986 }
@@ -1076,9 +1082,14 @@ where
10761082 sem_conv_config : self . sem_conv_config ,
10771083 } ) ;
10781084
1079- updates. update ( & mut builder) ;
1085+ let mut status = Status :: Unset ;
1086+ updates. update ( & mut builder, & mut status) ;
10801087 extensions. insert ( OtelData {
1081- state : OtelDataState :: Builder { builder, parent_cx } ,
1088+ state : OtelDataState :: Builder {
1089+ builder,
1090+ parent_cx,
1091+ status,
1092+ } ,
10821093 end_time : None ,
10831094 } ) ;
10841095 }
@@ -1152,9 +1163,11 @@ where
11521163 let mut extensions = span. extensions_mut ( ) ;
11531164 if let Some ( otel_data) = extensions. get_mut :: < OtelData > ( ) {
11541165 match & mut otel_data. state {
1155- OtelDataState :: Builder { builder, .. } => {
1166+ OtelDataState :: Builder {
1167+ builder, status, ..
1168+ } => {
11561169 // If the builder is present, then update it.
1157- updates. update ( builder) ;
1170+ updates. update ( builder, status ) ;
11581171 }
11591172 OtelDataState :: Context { current_cx, .. } => {
11601173 // If the Context has been created, then update the span.
@@ -1297,14 +1310,16 @@ where
12971310 }
12981311
12991312 match & mut otel_data. state {
1300- OtelDataState :: Builder { builder, .. } => {
1301- if builder. status == otel:: Status :: Unset
1313+ OtelDataState :: Builder {
1314+ builder, status, ..
1315+ } => {
1316+ if * status == otel:: Status :: Unset
13021317 && * meta. level ( ) == tracing_core:: Level :: ERROR
13031318 {
1304- builder . status = otel:: Status :: error ( "" ) ;
1319+ * status = otel:: Status :: error ( "" ) ;
13051320 }
13061321 if let Some ( builder_updates) = builder_updates {
1307- builder_updates. update ( builder) ;
1322+ builder_updates. update ( builder, status ) ;
13081323 }
13091324 if let Some ( ref mut events) = builder. events {
13101325 events. push ( otel_event) ;
@@ -1357,12 +1372,17 @@ where
13571372 } ) ;
13581373
13591374 match state {
1360- OtelDataState :: Builder { builder, parent_cx } => {
1375+ OtelDataState :: Builder {
1376+ builder,
1377+ parent_cx,
1378+ status,
1379+ } => {
13611380 // Don't create the context here just to get a SpanRef since it's costly
13621381 let mut span = builder. start_with_context ( & self . tracer , & parent_cx) ;
13631382 if let Some ( timings) = timings {
13641383 span. set_attributes ( timings)
13651384 } ;
1385+ span. set_status ( status) ;
13661386 if let Some ( end_time) = end_time {
13671387 span. end_with_timestamp ( end_time) ;
13681388 } else {
0 commit comments