Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spans): Add SDK information to spans #3178

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Add quotas to global config. ([#3086](https://github.com/getsentry/relay/pull/3086))
- Adds support for dynamic metric bucket encoding. ([#3137](https://github.com/getsentry/relay/pull/3137))
- Use statsdproxy to pre-aggregate metrics. ([#2425](https://github.com/getsentry/relay/pull/2425))
- Add SDK information to spans. ([#3178](https://github.com/getsentry/relay/pull/3178))

## 24.2.0

Expand Down
13 changes: 13 additions & 0 deletions relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub enum SpanTagKey {
TransactionMethod,
TransactionOp,
BrowserName,
SdkName,
SdkVersion,
Platform,
// `"true"` if the transaction was sent by a mobile SDK.
Mobile,
DeviceClass,
Expand Down Expand Up @@ -79,6 +82,9 @@ impl SpanTagKey {
SpanTagKey::Mobile => "mobile",
SpanTagKey::DeviceClass => "device.class",
SpanTagKey::BrowserName => "browser.name",
SpanTagKey::SdkName => "sdk.name",
SpanTagKey::SdkVersion => "sdk.version",
SpanTagKey::Platform => "platform",

SpanTagKey::Action => "action",
SpanTagKey::Category => "category",
Expand Down Expand Up @@ -240,6 +246,13 @@ pub fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, String> {
tags.insert(SpanTagKey::BrowserName, browser_name.into());
}

tags.insert(SpanTagKey::SdkName, event.sdk_name().into());
tags.insert(SpanTagKey::SdkVersion, event.sdk_version().into());
tags.insert(
SpanTagKey::Platform,
event.platform.as_str().unwrap_or("other").into(),
);

tags
}

Expand Down
1 change: 1 addition & 0 deletions relay-server/src/metrics_extraction/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ mod tests {
"release": "1.2.3",
"transaction": "gEt /api/:version/users/",
"transaction_info": {"source": "custom"},
"platform": "cocoa",
"contexts": {
"trace": {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ expression: "(&event.value().unwrap().spans, metrics)"
"mobile": "true",
"op": "app.start.cold",
"os.name": "iOS",
"platform": "cocoa",
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -76,7 +79,10 @@ expression: "(&event.value().unwrap().spans, metrics)"
"mobile": "true",
"op": "ui.load.initial_display",
"os.name": "iOS",
"platform": "cocoa",
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -120,7 +126,10 @@ expression: "(&event.value().unwrap().spans, metrics)"
"mobile": "true",
"op": "app.start.cold",
"os.name": "iOS",
"platform": "cocoa",
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -161,7 +170,10 @@ expression: "(&event.value().unwrap().spans, metrics)"
"mobile": "true",
"op": "custom.op",
"os.name": "iOS",
"platform": "cocoa",
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -204,7 +216,10 @@ expression: "(&event.value().unwrap().spans, metrics)"
"mobile": "true",
"op": "contentprovider.load",
"os.name": "iOS",
"platform": "cocoa",
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -247,7 +262,10 @@ expression: "(&event.value().unwrap().spans, metrics)"
"mobile": "true",
"op": "application.load",
"os.name": "iOS",
"platform": "cocoa",
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -314,7 +332,10 @@ expression: "(&event.value().unwrap().spans, metrics)"
"mobile": "true",
"op": "activity.load",
"os.name": "iOS",
"platform": "cocoa",
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down
3 changes: 3 additions & 0 deletions relay-server/src/services/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ impl StoreService {

span.duration_ms = ((span.end_timestamp - span.start_timestamp) * 1e3) as u32;
span.event_id = event_id;
span.organization_id = scoping.organization_id;
span.project_id = scoping.project_id.value();
span.retention_days = retention_days;
span.start_timestamp_ms = (span.start_timestamp * 1e3) as u64;
Expand Down Expand Up @@ -1521,6 +1522,8 @@ struct SpanKafkaMessage<'a> {

#[serde(borrow, default, skip_serializing_if = "Option::is_none")]
measurements: Option<BTreeMap<Cow<'a, str>, Option<SpanMeasurement>>>,
#[serde(default)]
organization_id: u64,
phacops marked this conversation as resolved.
Show resolved Hide resolved
#[serde(default, skip_serializing_if = "Option::is_none")]
parent_span_id: Option<&'a str>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
72 changes: 54 additions & 18 deletions tests/integration/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,20 +1382,24 @@ def test_span_extraction(
child_span = spans_consumer.get_span()
del child_span["received"]
assert child_span == {
"description": "GET /api/0/organizations/?member=1",
"duration_ms": int(duration.total_seconds() * 1e3),
"event_id": "cbf6960622e14a45abc1f03b2055b186",
"project_id": 42,
"retention_days": 90,
"description": "GET /api/0/organizations/?member=1",
"exclusive_time_ms": 500.0,
"is_segment": False,
"organization_id": 1,
"parent_span_id": "aaaaaaaaaaaaaaaa",
"project_id": 42,
"retention_days": 90,
"segment_id": "968cff94913ebb07",
"sentry_tags": {
"category": "http",
"description": "GET *",
"group": "37e3d9fab1ae9162",
"op": "http",
"platform": "other",
"sdk.name": "unknown",
"sdk.version": "unknown",
"transaction": "hi",
"transaction.op": "hi",
},
Expand All @@ -1406,20 +1410,28 @@ def test_span_extraction(

start_timestamp = datetime.fromisoformat(event["start_timestamp"])
end_timestamp = datetime.fromisoformat(event["timestamp"])
duration_ms = (end_timestamp - start_timestamp).total_seconds() * 1e3
duration_ms = int((end_timestamp - start_timestamp).total_seconds() * 1e3)

transaction_span = spans_consumer.get_span()
del transaction_span["received"]
assert transaction_span == {
"description": "hi",
"duration_ms": duration_ms,
"event_id": "cbf6960622e14a45abc1f03b2055b186",
"exclusive_time_ms": 2000.0,
"is_segment": True,
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"description": "hi",
"exclusive_time_ms": 2000,
"is_segment": True,
"segment_id": "968cff94913ebb07",
"sentry_tags": {"op": "hi", "transaction": "hi", "transaction.op": "hi"},
"sentry_tags": {
"op": "hi",
"platform": "other",
"sdk.name": "raven-node",
"sdk.version": "2.6.3",
"transaction": "hi",
"transaction.op": "hi",
},
"span_id": "968cff94913ebb07",
"start_timestamp_ms": int(
start_timestamp.replace(tzinfo=timezone.utc).timestamp() * 1e3
Expand Down Expand Up @@ -1623,6 +1635,7 @@ def test_span_ingestion(
"duration_ms": 500,
"exclusive_time_ms": 500.0,
"is_segment": True,
"organization_id": 1,
"parent_span_id": "",
"project_id": 42,
"retention_days": 90,
Expand All @@ -1641,6 +1654,7 @@ def test_span_ingestion(
"duration_ms": 1500,
"exclusive_time_ms": 345.0,
"is_segment": True,
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"segment_id": "bd429c44b67a3eb1",
Expand All @@ -1662,6 +1676,7 @@ def test_span_ingestion(
"duration_ms": 1500,
"exclusive_time_ms": 345.0,
"is_segment": True,
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"segment_id": "cd429c44b67a3eb1",
Expand All @@ -1675,6 +1690,7 @@ def test_span_ingestion(
"duration_ms": 500,
"exclusive_time_ms": 500.0,
"is_segment": True,
"organization_id": 1,
"parent_span_id": "",
"project_id": 42,
"retention_days": 90,
Expand All @@ -1691,6 +1707,7 @@ def test_span_ingestion(
"duration_ms": 1500,
"exclusive_time_ms": 345.0,
"is_segment": True,
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"segment_id": "ed429c44b67a3eb1",
Expand All @@ -1707,6 +1724,7 @@ def test_span_ingestion(
"duration_ms": 500,
"exclusive_time_ms": 500.0,
"is_segment": True,
"organization_id": 1,
"parent_span_id": "",
"project_id": 42,
"retention_days": 90,
Expand Down Expand Up @@ -1863,20 +1881,28 @@ def test_span_extraction_with_metrics_summary(

start_timestamp = datetime.fromisoformat(event["start_timestamp"])
end_timestamp = datetime.fromisoformat(event["timestamp"])
duration_ms = (end_timestamp - start_timestamp).total_seconds() * 1e3
duration_ms = int((end_timestamp - start_timestamp).total_seconds() * 1e3)

transaction_span = spans_consumer.get_span()
del transaction_span["received"]
assert transaction_span == {
"description": "hi",
"duration_ms": duration_ms,
"event_id": "cbf6960622e14a45abc1f03b2055b186",
"exclusive_time_ms": 2000.0,
"is_segment": True,
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"description": "hi",
"exclusive_time_ms": 2000,
"is_segment": True,
"segment_id": "968cff94913ebb07",
"sentry_tags": {"op": "hi", "transaction": "hi", "transaction.op": "hi"},
"sentry_tags": {
"op": "hi",
"platform": "other",
"sdk.name": "raven-node",
"sdk.version": "2.6.3",
"transaction": "hi",
"transaction.op": "hi",
},
"span_id": "968cff94913ebb07",
"start_timestamp_ms": int(
start_timestamp.replace(tzinfo=timezone.utc).timestamp() * 1e3
Expand Down Expand Up @@ -1937,21 +1963,29 @@ def test_span_extraction_with_ddm_missing_values(
transaction_span = spans_consumer.get_span()
del transaction_span["received"]
assert transaction_span == {
"description": "hi",
"duration_ms": duration_ms,
"event_id": "cbf6960622e14a45abc1f03b2055b186",
"exclusive_time_ms": 2000.0,
"is_segment": True,
"measurements": {},
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"description": "hi",
"exclusive_time_ms": 2000,
"is_segment": True,
"segment_id": "968cff94913ebb07",
"sentry_tags": {"op": "hi", "transaction": "hi", "transaction.op": "hi"},
"sentry_tags": {
"op": "hi",
"platform": "other",
"sdk.name": "raven-node",
"sdk.version": "2.6.3",
"transaction": "hi",
"transaction.op": "hi",
},
"span_id": "968cff94913ebb07",
"start_timestamp_ms": int(
start_timestamp.replace(tzinfo=timezone.utc).timestamp() * 1e3
),
"trace_id": "a0fa8803753e40fd8124b21eeb2986b5",
"measurements": {},
}

spans_consumer.assert_empty()
Expand Down Expand Up @@ -2157,6 +2191,7 @@ def test_span_ingestion_with_performance_scores(
"duration_ms": 1500,
"exclusive_time_ms": 345.0,
"is_segment": True,
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"segment_id": "bd429c44b67a3eb1",
Expand Down Expand Up @@ -2190,6 +2225,7 @@ def test_span_ingestion_with_performance_scores(
"duration_ms": 1500,
"exclusive_time_ms": 345.0,
"is_segment": True,
"organization_id": 1,
"project_id": 42,
"retention_days": 90,
"segment_id": "bd429c44b67a3eb1",
Expand Down
Loading