@@ -163,7 +163,7 @@ struct SpanBuilderUpdates {
163
163
}
164
164
165
165
impl SpanBuilderUpdates {
166
- fn update ( self , span_builder : & mut SpanBuilder ) {
166
+ fn update ( self , span_builder : & mut SpanBuilder , s : & mut Status ) {
167
167
let Self {
168
168
name,
169
169
span_kind,
@@ -178,7 +178,7 @@ impl SpanBuilderUpdates {
178
178
span_builder. span_kind = Some ( span_kind) ;
179
179
}
180
180
if let Some ( status) = status {
181
- span_builder . status = status;
181
+ * s = status;
182
182
}
183
183
if let Some ( attributes) = attributes {
184
184
if let Some ( builder_attributes) = & mut span_builder. attributes {
@@ -973,8 +973,14 @@ where
973
973
fn start_cx ( & self , otel_data : & mut OtelData ) {
974
974
if let OtelDataState :: Context { .. } = & otel_data. state {
975
975
// 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) ;
978
984
let current_cx = parent_cx. with_span ( span) ;
979
985
otel_data. state = OtelDataState :: Context { current_cx } ;
980
986
}
@@ -1076,9 +1082,14 @@ where
1076
1082
sem_conv_config : self . sem_conv_config ,
1077
1083
} ) ;
1078
1084
1079
- updates. update ( & mut builder) ;
1085
+ let mut status = Status :: Unset ;
1086
+ updates. update ( & mut builder, & mut status) ;
1080
1087
extensions. insert ( OtelData {
1081
- state : OtelDataState :: Builder { builder, parent_cx } ,
1088
+ state : OtelDataState :: Builder {
1089
+ builder,
1090
+ parent_cx,
1091
+ status,
1092
+ } ,
1082
1093
end_time : None ,
1083
1094
} ) ;
1084
1095
}
@@ -1152,9 +1163,11 @@ where
1152
1163
let mut extensions = span. extensions_mut ( ) ;
1153
1164
if let Some ( otel_data) = extensions. get_mut :: < OtelData > ( ) {
1154
1165
match & mut otel_data. state {
1155
- OtelDataState :: Builder { builder, .. } => {
1166
+ OtelDataState :: Builder {
1167
+ builder, status, ..
1168
+ } => {
1156
1169
// If the builder is present, then update it.
1157
- updates. update ( builder) ;
1170
+ updates. update ( builder, status ) ;
1158
1171
}
1159
1172
OtelDataState :: Context { current_cx, .. } => {
1160
1173
// If the Context has been created, then update the span.
@@ -1297,14 +1310,16 @@ where
1297
1310
}
1298
1311
1299
1312
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
1302
1317
&& * meta. level ( ) == tracing_core:: Level :: ERROR
1303
1318
{
1304
- builder . status = otel:: Status :: error ( "" ) ;
1319
+ * status = otel:: Status :: error ( "" ) ;
1305
1320
}
1306
1321
if let Some ( builder_updates) = builder_updates {
1307
- builder_updates. update ( builder) ;
1322
+ builder_updates. update ( builder, status ) ;
1308
1323
}
1309
1324
if let Some ( ref mut events) = builder. events {
1310
1325
events. push ( otel_event) ;
@@ -1357,12 +1372,17 @@ where
1357
1372
} ) ;
1358
1373
1359
1374
match state {
1360
- OtelDataState :: Builder { builder, parent_cx } => {
1375
+ OtelDataState :: Builder {
1376
+ builder,
1377
+ parent_cx,
1378
+ status,
1379
+ } => {
1361
1380
// Don't create the context here just to get a SpanRef since it's costly
1362
1381
let mut span = builder. start_with_context ( & self . tracer , & parent_cx) ;
1363
1382
if let Some ( timings) = timings {
1364
1383
span. set_attributes ( timings)
1365
1384
} ;
1385
+ span. set_status ( status) ;
1366
1386
if let Some ( end_time) = end_time {
1367
1387
span. end_with_timestamp ( end_time) ;
1368
1388
} else {
0 commit comments