@@ -9,7 +9,7 @@ use tracing_subscriber::layer::Context;
99use tracing_subscriber:: registry:: LookupSpan ;
1010
1111use super :: layer:: SentrySpanData ;
12- use crate :: TAGS_PREFIX ;
12+ use crate :: { SpanPropagation , TAGS_PREFIX } ;
1313
1414/// Converts a [`tracing_core::Level`] to a Sentry [`Level`]
1515fn convert_tracing_level ( level : & tracing_core:: Level ) -> Level {
@@ -53,40 +53,34 @@ fn extract_event_data(event: &tracing_core::Event) -> (Option<String>, FieldVisi
5353
5454fn extract_event_data_with_context < S > (
5555 event : & tracing_core:: Event ,
56- ctx : Option < Context < S > > ,
56+ ctx : Option < ( SpanPropagation , Context < S > ) > ,
5757) -> ( Option < String > , FieldVisitor )
5858where
5959 S : Subscriber + for < ' a > LookupSpan < ' a > ,
6060{
6161 let ( message, mut visitor) = extract_event_data ( event) ;
6262
6363 // Add the context fields of every parent span.
64- let current_span = ctx. as_ref ( ) . and_then ( |ctx| {
64+ let current_span = ctx. as_ref ( ) . and_then ( |( propagation , ctx) | {
6565 event
6666 . parent ( )
67- . and_then ( |id| ctx. span ( id) )
68- . or_else ( || ctx. lookup_current ( ) )
67+ . and_then ( |id| ctx. span ( id) . map ( |span| ( * propagation , span ) ) )
68+ . or_else ( || ctx. lookup_current ( ) . map ( |span| ( * propagation , span ) ) )
6969 } ) ;
70- if let Some ( span) = current_span {
70+ if let Some ( ( propagation , span) ) = current_span {
7171 for span in span. scope ( ) {
7272 let name = span. name ( ) ;
7373 let ext = span. extensions ( ) ;
7474 if let Some ( span_data) = ext. get :: < SentrySpanData > ( ) {
7575 match & span_data. sentry_span {
7676 TransactionOrSpan :: Span ( span) => {
7777 for ( key, value) in span. data ( ) . iter ( ) {
78- if key != "message" {
79- let key = format ! ( "{}:{}" , name, key) ;
80- visitor. json_values . insert ( key, value. clone ( ) ) ;
81- }
78+ visitor. propagate_span_attr ( key, value, propagation, name) ;
8279 }
8380 }
8481 TransactionOrSpan :: Transaction ( transaction) => {
8582 for ( key, value) in transaction. data ( ) . iter ( ) {
86- if key != "message" {
87- let key = format ! ( "{}:{}" , name, key) ;
88- visitor. json_values . insert ( key, value. clone ( ) ) ;
89- }
83+ visitor. propagate_span_attr ( key, value, propagation, name) ;
9084 }
9185 }
9286 }
@@ -105,6 +99,26 @@ pub(crate) struct FieldVisitor {
10599}
106100
107101impl FieldVisitor {
102+ fn propagate_span_attr (
103+ & mut self ,
104+ key : & str ,
105+ value : & Value ,
106+ span_propagation : SpanPropagation ,
107+ span_name : & str ,
108+ ) {
109+ if key != "message" {
110+ if span_propagation. is_tags_enabled ( ) && key. starts_with ( TAGS_PREFIX ) {
111+ //Propagate tags as it is, it will be extracted later on
112+ if !self . json_values . contains_key ( key) {
113+ self . json_values . insert ( key. to_owned ( ) , value. clone ( ) ) ;
114+ }
115+ } else if span_propagation. is_attrs_enabled ( ) {
116+ let key = format ! ( "{}:{}" , span_name, key) ;
117+ self . json_values . insert ( key, value. clone ( ) ) ;
118+ }
119+ }
120+ }
121+
108122 fn record < T : Into < Value > > ( & mut self , field : & Field , value : T ) {
109123 self . json_values
110124 . insert ( field. name ( ) . to_owned ( ) , value. into ( ) ) ;
@@ -143,12 +157,17 @@ impl Visit for FieldVisitor {
143157/// Creates a [`Breadcrumb`] from a given [`tracing_core::Event`]
144158pub fn breadcrumb_from_event < ' context , S > (
145159 event : & tracing_core:: Event ,
146- ctx : impl Into < Option < Context < ' context , S > > > ,
160+ ctx : impl Into < Option < ( SpanPropagation , Context < ' context , S > ) > > ,
147161) -> Breadcrumb
148162where
149163 S : Subscriber + for < ' a > LookupSpan < ' a > ,
150164{
151- let ( message, visitor) = extract_event_data_with_context ( event, ctx. into ( ) ) ;
165+ let ctx = match ctx. into ( ) {
166+ Some ( ( propagation, ctx) ) if propagation. is_attrs_enabled ( ) => Some ( ( propagation, ctx) ) ,
167+ //Breadcrumb has no tags, so propagate only attributes
168+ _ => None ,
169+ } ;
170+ let ( message, visitor) = extract_event_data_with_context ( event, ctx) ;
152171 Breadcrumb {
153172 category : Some ( event. metadata ( ) . target ( ) . to_owned ( ) ) ,
154173 ty : "log" . into ( ) ,
@@ -219,7 +238,7 @@ fn contexts_from_event(
219238/// Creates an [`Event`] from a given [`tracing_core::Event`]
220239pub fn event_from_event < ' context , S > (
221240 event : & tracing_core:: Event ,
222- ctx : impl Into < Option < Context < ' context , S > > > ,
241+ ctx : impl Into < Option < ( SpanPropagation , Context < ' context , S > ) > > ,
223242) -> Event < ' static >
224243where
225244 S : Subscriber + for < ' a > LookupSpan < ' a > ,
@@ -239,7 +258,7 @@ where
239258/// Creates an exception [`Event`] from a given [`tracing_core::Event`]
240259pub fn exception_from_event < ' context , S > (
241260 event : & tracing_core:: Event ,
242- ctx : impl Into < Option < Context < ' context , S > > > ,
261+ ctx : impl Into < Option < ( SpanPropagation , Context < ' context , S > ) > > ,
243262) -> Event < ' static >
244263where
245264 S : Subscriber + for < ' a > LookupSpan < ' a > ,
0 commit comments