Skip to content

Commit

Permalink
fix(spans): Add a description to the segment as well (#2512)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Sep 19, 2023
1 parent aa324fa commit 3b265f2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Add a nanojoule unit for profile measurements. ([#2478](https://github.com/getsentry/relay/pull/2478))
- Add a timestamp field to report profile's start time on Android. ([#2486](https://github.com/getsentry/relay/pull/2486))
- Filter span metrics extraction based on features. ([#2511](https://github.com/getsentry/relay/pull/2511), [#2520](https://github.com/getsentry/relay/pull/2520))
- Extract shared tags on the segment. ([#2512](https://github.com/getsentry/relay/pull/2512))

## 23.8.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub(crate) fn extract_span_tags(event: &mut Event, config: &Config) {
}

/// Extracts tags shared by every span.
fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, Value> {
pub fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, Value> {
let mut tags = BTreeMap::<SpanTagKey, Value>::new();

if let Some(release) = event.release.as_str() {
Expand Down
5 changes: 3 additions & 2 deletions relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ pub struct Span {
impl From<&Event> for Span {
fn from(event: &Event) -> Self {
let mut span = Self {
timestamp: event.timestamp.clone(),
start_timestamp: event.start_timestamp.clone(),
description: event.transaction.clone(),
is_segment: Some(true).into(),
start_timestamp: event.start_timestamp.clone(),
timestamp: event.timestamp.clone(),
..Default::default()
};

Expand Down
27 changes: 20 additions & 7 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use {
crate::actors::envelopes::SendMetrics,
crate::actors::project_cache::UpdateRateLimits,
crate::utils::{EnvelopeLimiter, MetricsLimiter},
relay_event_normalization::{StoreConfig, StoreProcessor},
relay_event_normalization::{span, StoreConfig, StoreProcessor},
relay_event_schema::protocol::ProfileContext,
relay_quotas::{RateLimitingError, RedisRateLimiter},
symbolic_unreal::{Unreal4Error, Unreal4ErrorKind},
Expand Down Expand Up @@ -2259,12 +2259,6 @@ impl EnvelopeProcessorService {
return;
};

// Extract transaction as a span.
let Some(event) = state.event.value() else {
return;
};
let transaction_span: Span = event.into();

let mut add_span = |span: Annotated<Span>| {
let span = match span.to_json() {
Ok(span) => span,
Expand All @@ -2278,6 +2272,13 @@ impl EnvelopeProcessorService {
state.managed_envelope.envelope_mut().add_item(item);
};

let Some(event) = state.event.value() else {
return;
};

// Extract transaction as a span.
let mut transaction_span: Span = event.into();

let all_modules_enabled = state
.project_state
.has_feature(Feature::SpanMetricsExtractionAllModules);
Expand Down Expand Up @@ -2308,6 +2309,18 @@ impl EnvelopeProcessorService {
}

if all_modules_enabled {
// Extract tags to add to this span as well
let shared_tags = span::tag_extraction::extract_shared_tags(event);
let data = transaction_span
.data
.value_mut()
.get_or_insert_with(Default::default);
data.extend(
shared_tags
.clone()
.into_iter()
.map(|(k, v)| (k.to_string(), Annotated::new(v))),
);
add_span(transaction_span.into());
}
}
Expand Down
9 changes: 8 additions & 1 deletion tests/integration/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ def test_processing_quotas(
elif event_type == "error":
transform = make_error
else:
transform = lambda e: e

def transform(e):
return e

for i in range(5):
# send using the first dsn
Expand Down Expand Up @@ -1247,6 +1249,11 @@ def test_spans(
"event_id": "cbf6960622e14a45abc1f03b2055b186",
"project_id": 42,
"span": {
"data": {
"transaction": "hi",
"transaction.op": "hi",
},
"description": "hi",
"exclusive_time": 2000.0,
"is_segment": True,
"op": "hi",
Expand Down

0 comments on commit 3b265f2

Please sign in to comment.