@@ -54,21 +54,22 @@ fn extract_event_data(event: &tracing_core::Event) -> (Option<String>, FieldVisi
54
54
55
55
fn extract_event_data_with_context < S > (
56
56
event : & tracing_core:: Event ,
57
- ctx : Option < ( SpanPropagation , Context < S > ) > ,
57
+ ctx : Context < S > ,
58
+ propagation : Option < SpanPropagation > ,
58
59
) -> ( Option < String > , FieldVisitor )
59
60
where
60
61
S : Subscriber + for < ' a > LookupSpan < ' a > ,
61
62
{
62
63
let ( message, mut visitor) = extract_event_data ( event) ;
63
64
64
- // Add the context fields of every parent span.
65
- let current_span = ctx . as_ref ( ) . and_then ( |( propagation, ctx ) | {
65
+ // Add the context fields of every parent span, if propagation is enabled
66
+ let propagation_span = propagation . and_then ( |propagation| {
66
67
event
67
68
. parent ( )
68
- . and_then ( |id| ctx. span ( id) . map ( |span| ( * propagation, span) ) )
69
- . or_else ( || ctx. lookup_current ( ) . map ( |span| ( * propagation, span) ) )
69
+ . and_then ( |id| ctx. span ( id) . map ( |span| ( propagation, span) ) )
70
+ . or_else ( || ctx. lookup_current ( ) . map ( |span| ( propagation, span) ) )
70
71
} ) ;
71
- if let Some ( ( propagation, span) ) = current_span {
72
+ if let Some ( ( propagation, span) ) = propagation_span {
72
73
for span in span. scope ( ) {
73
74
let name = span. name ( ) ;
74
75
let ext = span. extensions ( ) ;
@@ -172,19 +173,19 @@ impl Visit for FieldVisitor {
172
173
/// Creates a [`Breadcrumb`] from a given [`tracing_core::Event`]
173
174
pub fn breadcrumb_from_event < ' context , S > (
174
175
event : & tracing_core:: Event ,
175
- ctx : impl Into < Option < ( SpanPropagation , Context < ' context , S > ) > > ,
176
+ ctx : Context < ' context , S > ,
177
+ mut propagation : Option < SpanPropagation > ,
176
178
) -> Breadcrumb
177
179
where
178
180
S : Subscriber + for < ' a > LookupSpan < ' a > ,
179
181
{
180
- let ctx = match ctx. into ( ) {
181
- Some ( ( propagation, ctx) ) if propagation. is_attrs_enabled ( ) => {
182
- Some ( ( SpanPropagation :: Attributes , ctx) )
182
+ if let Some ( propagation) = propagation. as_mut ( ) {
183
+ if propagation. is_attrs_enabled ( ) {
184
+ //Breadcrumb has no tags, so propagate only attributes
185
+ * propagation = SpanPropagation :: Attributes ;
183
186
}
184
- //Breadcrumb has no tags, so propagate only attributes
185
- _ => None ,
186
- } ;
187
- let ( message, visitor) = extract_event_data_with_context ( event, ctx) ;
187
+ }
188
+ let ( message, visitor) = extract_event_data_with_context ( event, ctx, propagation) ;
188
189
Breadcrumb {
189
190
category : Some ( event. metadata ( ) . target ( ) . to_owned ( ) ) ,
190
191
ty : "log" . into ( ) ,
@@ -255,12 +256,13 @@ fn contexts_from_event(
255
256
/// Creates an [`Event`] from a given [`tracing_core::Event`]
256
257
pub fn event_from_event < ' context , S > (
257
258
event : & tracing_core:: Event ,
258
- ctx : impl Into < Option < ( SpanPropagation , Context < ' context , S > ) > > ,
259
+ ctx : Context < ' context , S > ,
260
+ propagation : Option < SpanPropagation > ,
259
261
) -> Event < ' static >
260
262
where
261
263
S : Subscriber + for < ' a > LookupSpan < ' a > ,
262
264
{
263
- let ( message, mut visitor) = extract_event_data_with_context ( event, ctx. into ( ) ) ;
265
+ let ( message, mut visitor) = extract_event_data_with_context ( event, ctx, propagation ) ;
264
266
265
267
Event {
266
268
logger : Some ( event. metadata ( ) . target ( ) . to_owned ( ) ) ,
@@ -275,7 +277,8 @@ where
275
277
/// Creates an exception [`Event`] from a given [`tracing_core::Event`]
276
278
pub fn exception_from_event < ' context , S > (
277
279
event : & tracing_core:: Event ,
278
- ctx : impl Into < Option < ( SpanPropagation , Context < ' context , S > ) > > ,
280
+ ctx : Context < ' context , S > ,
281
+ propagation : Option < SpanPropagation > ,
279
282
) -> Event < ' static >
280
283
where
281
284
S : Subscriber + for < ' a > LookupSpan < ' a > ,
@@ -285,7 +288,7 @@ where
285
288
// information for this. However, it may contain a serialized error which we can parse to emit
286
289
// an exception record.
287
290
#[ allow( unused_mut) ]
288
- let ( mut message, visitor) = extract_event_data_with_context ( event, ctx. into ( ) ) ;
291
+ let ( mut message, visitor) = extract_event_data_with_context ( event, ctx, propagation ) ;
289
292
let FieldVisitor {
290
293
mut exceptions,
291
294
mut json_values,
0 commit comments