@@ -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 {
@@ -974,8 +974,16 @@ where
974
974
fn start_cx ( & self , otel_data : & mut OtelData ) {
975
975
if let OtelDataState :: Context { .. } = & otel_data. state {
976
976
// 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
+ }
979
987
let current_cx = parent_cx. with_span ( span) ;
980
988
otel_data. state = OtelDataState :: Context { current_cx } ;
981
989
}
@@ -1077,9 +1085,14 @@ where
1077
1085
sem_conv_config : self . sem_conv_config ,
1078
1086
} ) ;
1079
1087
1080
- updates. update ( & mut builder) ;
1088
+ let mut status = Status :: Unset ;
1089
+ updates. update ( & mut builder, & mut status) ;
1081
1090
extensions. insert ( OtelData {
1082
- state : OtelDataState :: Builder { builder, parent_cx } ,
1091
+ state : OtelDataState :: Builder {
1092
+ builder,
1093
+ parent_cx,
1094
+ status,
1095
+ } ,
1083
1096
end_time : None ,
1084
1097
} ) ;
1085
1098
}
@@ -1153,9 +1166,11 @@ where
1153
1166
let mut extensions = span. extensions_mut ( ) ;
1154
1167
if let Some ( otel_data) = extensions. get_mut :: < OtelData > ( ) {
1155
1168
match & mut otel_data. state {
1156
- OtelDataState :: Builder { builder, .. } => {
1169
+ OtelDataState :: Builder {
1170
+ builder, status, ..
1171
+ } => {
1157
1172
// If the builder is present, then update it.
1158
- updates. update ( builder) ;
1173
+ updates. update ( builder, status ) ;
1159
1174
}
1160
1175
OtelDataState :: Context { current_cx, .. } => {
1161
1176
// If the Context has been created, then update the span.
@@ -1298,14 +1313,16 @@ where
1298
1313
}
1299
1314
1300
1315
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
1303
1320
&& * meta. level ( ) == tracing_core:: Level :: ERROR
1304
1321
{
1305
- builder . status = otel:: Status :: error ( "" ) ;
1322
+ * status = otel:: Status :: error ( "" ) ;
1306
1323
}
1307
1324
if let Some ( builder_updates) = builder_updates {
1308
- builder_updates. update ( builder) ;
1325
+ builder_updates. update ( builder, status ) ;
1309
1326
}
1310
1327
if let Some ( ref mut events) = builder. events {
1311
1328
events. push ( otel_event) ;
@@ -1358,12 +1375,19 @@ where
1358
1375
} ) ;
1359
1376
1360
1377
match state {
1361
- OtelDataState :: Builder { builder, parent_cx } => {
1378
+ OtelDataState :: Builder {
1379
+ builder,
1380
+ parent_cx,
1381
+ status,
1382
+ } => {
1362
1383
// Don't create the context here just to get a SpanRef since it's costly
1363
1384
let mut span = builder. start_with_context ( & self . tracer , & parent_cx) ;
1364
1385
if let Some ( timings) = timings {
1365
1386
span. set_attributes ( timings)
1366
1387
} ;
1388
+ if status != Status :: Unset {
1389
+ span. set_status ( status) ;
1390
+ }
1367
1391
if let Some ( end_time) = end_time {
1368
1392
span. end_with_timestamp ( end_time) ;
1369
1393
} else {
0 commit comments