Skip to content

Commit

Permalink
tracing: unique field names for different spans
Browse files Browse the repository at this point in the history
  • Loading branch information
tsionyx committed Dec 2, 2023
1 parent 6300b53 commit 6a774ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
17 changes: 11 additions & 6 deletions sentry-tracing/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ where
.and_then(|v| v.as_str().map(|s| s.to_owned()));

// Add the context fields of every parent span.
// Higher spans' values have higher precedence
// in the case of field name clashes.
let current_span = ctx.as_ref().and_then(|ctx| {
event
.parent()
Expand All @@ -61,14 +59,21 @@ where
});
if let Some(span) = current_span {
for span in span.scope() {
let name = span.name();
let ext = span.extensions();
if let Some(span_data) = ext.get::<SentrySpanData>() {
if let TransactionOrSpan::Span(span) = &span_data.sentry_span {
for (key, value) in span.data().iter() {
if key != "message" {
visitor.json_values.insert(key.clone(), value.clone());
match &span_data.sentry_span {
TransactionOrSpan::Span(span) => {
for (key, value) in span.data().iter() {
if key != "message" {
let key = format!("{}:{}", name, key);
visitor.json_values.insert(key, value.clone());
}
}
}
TransactionOrSpan::Transaction(transaction) => {
// TODO: extract data from transaction
}
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions sentry-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,8 @@ impl<S> SentryLayer<S> {
self
}


/// Enable every parent span's attributes to be sent along with own event's attributes.
///
/// Note that the higher the span in the span chain, the more precedence its values have.
///
/// E.g.:
/// - if the event has a field _foo_ and one of its spans
/// has attribute with the same name, the span's value will be used;
/// - if the direct parent has a field _bar_ and one of its parent span
/// has attribute with the same name, the parent span's value will be used.
#[must_use]
pub fn enable_span_attributes(mut self) -> Self {
self.with_span_attributes = true;
Expand Down

0 comments on commit 6a774ee

Please sign in to comment.