From f56e54bc6d1e927c3864a837a73ef7b26237331e Mon Sep 17 00:00:00 2001 From: George Gritsouk <989898+gggritso@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:22:49 -0400 Subject: [PATCH] feat(perf): Extract `span.status_code` tag for HTTP spans (#3245) We need this to do status code breakdowns for the HTTP module. --- CHANGELOG.md | 2 +- relay-dynamic-config/src/defaults.rs | 8 ++ relay-server/src/metrics_extraction/event.rs | 13 ++++ ...n__event__tests__extract_span_metrics.snap | 74 +++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 085227202a..fd67e6ffd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ - Enable HTTP compression for all APIs. ([#3233](https://github.com/getsentry/relay/pull/3233)) - Add `process.load` span to ingested mobile span ops. ([#3227](https://github.com/getsentry/relay/pull/3227)) - Enforce rate limits for standalone spans. ([#3238](https://github.com/getsentry/relay/pull/3238)) - +- Extract `span.status_code` tag for HTTP spans. ([#3245](https://github.com/getsentry/relay/pull/3245)) **Bug Fixes**: diff --git a/relay-dynamic-config/src/defaults.rs b/relay-dynamic-config/src/defaults.rs index b8d69b0bdc..cc2e887aac 100644 --- a/relay-dynamic-config/src/defaults.rs +++ b/relay-dynamic-config/src/defaults.rs @@ -209,6 +209,10 @@ fn span_metrics() -> impl IntoIterator { Tag::with_key("resource.render_blocking_status") .from_field("span.sentry_tags.resource.render_blocking_status") .when(is_resource.clone()), + // HTTP module: + Tag::with_key("span.status_code") + .from_field("span.sentry_tags.status_code") + .when(is_http.clone()), ], }, MetricSpec { @@ -260,6 +264,10 @@ fn span_metrics() -> impl IntoIterator { Tag::with_key("resource.render_blocking_status") .from_field("span.sentry_tags.resource.render_blocking_status") .when(is_resource.clone()), + // HTTP module: + Tag::with_key("span.status_code") + .from_field("span.sentry_tags.status_code") + .when(is_http.clone()), ], }, MetricSpec { diff --git a/relay-server/src/metrics_extraction/event.rs b/relay-server/src/metrics_extraction/event.rs index 63598da12a..3b86f70216 100644 --- a/relay-server/src/metrics_extraction/event.rs +++ b/relay-server/src/metrics_extraction/event.rs @@ -166,6 +166,19 @@ mod tests { "http.method": "GET" } }, + { + "description": "GET /hi/this/is/just/the/path", + "op": "http.client", + "parent_span_id": "8f5a2b8768cafb4e", + "span_id": "bd429c44b67a3eb4", + "start_timestamp": 1597976300.0000000, + "timestamp": 1597976302.0000000, + "trace_id": "ff62a8b040f340bda5d830223def1d81", + "data": { + "http.method": "GET", + "status_code": "500" + } + }, { "description": "POST http://127.0.0.1:1234/api/hi", "op": "http.client", diff --git a/relay-server/src/metrics_extraction/snapshots/relay_server__metrics_extraction__event__tests__extract_span_metrics.snap b/relay-server/src/metrics_extraction/snapshots/relay_server__metrics_extraction__event__tests__extract_span_metrics.snap index f9daf214df..6b3ee6cc29 100644 --- a/relay-server/src/metrics_extraction/snapshots/relay_server__metrics_extraction__event__tests__extract_span_metrics.snap +++ b/relay-server/src/metrics_extraction/snapshots/relay_server__metrics_extraction__event__tests__extract_span_metrics.snap @@ -213,6 +213,56 @@ expression: metrics "span.op": "http.client", }, }, + Bucket { + timestamp: UnixTimestamp(1597976302), + width: 0, + name: "d:spans/exclusive_time@millisecond", + value: Distribution( + [ + 2000.0, + ], + ), + tags: { + "environment": "fake_environment", + "span.category": "http", + "span.description": "GET *", + "span.group": "37e3d9fab1ae9162", + "span.op": "http.client", + "span.status_code": "500", + "transaction": "gEt /api/:version/users/", + "transaction.method": "POST", + }, + }, + Bucket { + timestamp: UnixTimestamp(1597976302), + width: 0, + name: "d:spans/exclusive_time_light@millisecond", + value: Distribution( + [ + 2000.0, + ], + ), + tags: { + "environment": "fake_environment", + "span.category": "http", + "span.description": "GET *", + "span.group": "37e3d9fab1ae9162", + "span.op": "http.client", + "span.status_code": "500", + }, + }, + Bucket { + timestamp: UnixTimestamp(1597976302), + width: 0, + name: "c:spans/count_per_op@none", + value: Counter( + 1.0, + ), + tags: { + "span.category": "http", + "span.op": "http.client", + }, + }, Bucket { timestamp: UnixTimestamp(1597976302), width: 0, @@ -228,6 +278,7 @@ expression: metrics "span.description": "POST http://127.0.0.1:1234", "span.group": "464fe695f9cf639c", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -247,6 +298,7 @@ expression: metrics "span.description": "POST http://127.0.0.1:1234", "span.group": "464fe695f9cf639c", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -277,6 +329,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -297,6 +350,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -327,6 +381,7 @@ expression: metrics "span.domain": "targetdomain.tld:1234", "span.group": "72ab88b506cb04b2", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -347,6 +402,7 @@ expression: metrics "span.domain": "targetdomain.tld:1234", "span.group": "72ab88b506cb04b2", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -377,6 +433,7 @@ expression: metrics "span.domain": "targetdomain:1234", "span.group": "c8e531abe96ff360", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -397,6 +454,7 @@ expression: metrics "span.domain": "targetdomain:1234", "span.group": "c8e531abe96ff360", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -427,6 +485,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -447,6 +506,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -477,6 +537,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -497,6 +558,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -1726,6 +1788,7 @@ expression: metrics "span.description": "POST http://127.0.0.1:1234", "span.group": "464fe695f9cf639c", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -1745,6 +1808,7 @@ expression: metrics "span.description": "POST http://127.0.0.1:1234", "span.group": "464fe695f9cf639c", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -1775,6 +1839,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -1795,6 +1860,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -1825,6 +1891,7 @@ expression: metrics "span.domain": "targetdomain.tld:1234", "span.group": "72ab88b506cb04b2", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -1845,6 +1912,7 @@ expression: metrics "span.domain": "targetdomain.tld:1234", "span.group": "72ab88b506cb04b2", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -1875,6 +1943,7 @@ expression: metrics "span.domain": "targetdomain:1234", "span.group": "c8e531abe96ff360", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -1895,6 +1964,7 @@ expression: metrics "span.domain": "targetdomain:1234", "span.group": "c8e531abe96ff360", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -1925,6 +1995,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -1945,6 +2016,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket { @@ -1975,6 +2047,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", "transaction": "gEt /api/:version/users/", "transaction.method": "POST", }, @@ -1995,6 +2068,7 @@ expression: metrics "span.domain": "*.domain.tld:1234", "span.group": "86818d1c74ecfc66", "span.op": "http.client", + "span.status_code": "200", }, }, Bucket {