Skip to content

Commit

Permalink
feat(event-schema): Look up data attributes in tags (#3751)
Browse files Browse the repository at this point in the history
SDKs send certain attributes in `span.tags` rather than `span.data`. To
consolidate access and make all data accessible via a single key, this
PR makes the getter implementation on spans fall back to `tags` if a key
is not present on `data`.
  • Loading branch information
jan-auer authored Jun 20, 2024
1 parent 64c3253 commit 6f5b38f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Improve flush time calculation in metrics aggregator. ([#3726](https://github.com/getsentry/relay/pull/3726))
- Default `client` of `RequestMeta` to `relay-http` for incoming monitor requests. ([#3739](https://github.com/getsentry/relay/pull/3739))
- Normalize events once in the ingestion pipeline, relying on item headers. ([#3730](https://github.com/getsentry/relay/pull/3730))
- Provide access to values in `span.tags.*` via `span.data.*`. This serves as an opaque fallback to consolidate data attributes. ([#3751](https://github.com/getsentry/relay/pull/3751))

## 24.5.1

Expand Down
15 changes: 14 additions & 1 deletion relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ pub struct Span {
pub other: Object<Value>,
}

impl Span {
/// Returns the value of an attribute on the span.
///
/// This primarily looks up the attribute in the `data` object, but falls back to the `tags`
/// object if the attribute is not found.
fn attribute(&self, key: &str) -> Option<Val<'_>> {
Some(match self.data.value()?.get_value(key) {
Some(value) => value,
None => self.tags.value()?.get(key)?.as_str()?.into(),
})
}
}

impl Getter for Span {
fn get_value(&self, path: &str) -> Option<Val<'_>> {
let span_prefix = path.strip_prefix("span.");
Expand All @@ -136,7 +149,7 @@ impl Getter for Span {
if let Some(key) = path.strip_prefix("tags.") {
self.tags.value()?.get(key)?.as_str()?.into()
} else if let Some(key) = path.strip_prefix("data.") {
self.data.value()?.get_value(key)?
self.attribute(key)?
} else if let Some(key) = path.strip_prefix("sentry_tags.") {
self.sentry_tags.value()?.get(key)?.as_str()?.into()
} else if let Some(rest) = path.strip_prefix("measurements.") {
Expand Down

0 comments on commit 6f5b38f

Please # to comment.