From 85b35144a7387b361e51bac4085aa1572fe49ab7 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Fri, 1 Jul 2022 13:47:23 +0200 Subject: [PATCH 1/7] feat(protocol): Add transaction_source to events --- relay-general/src/protocol/event.rs | 7 +- relay-general/src/protocol/mod.rs | 2 + relay-general/src/protocol/transaction.rs | 169 ++++++++++++++++++ .../test_fixtures__event_schema.snap | 75 ++++++++ 4 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 relay-general/src/protocol/transaction.rs diff --git a/relay-general/src/protocol/event.rs b/relay-general/src/protocol/event.rs index 1dff95f9a6e..72252ff265c 100644 --- a/relay-general/src/protocol/event.rs +++ b/relay-general/src/protocol/event.rs @@ -12,7 +12,8 @@ use crate::processor::ProcessValue; use crate::protocol::{ Breadcrumb, Breakdowns, ClientSdkInfo, Contexts, Csp, DebugMeta, Exception, ExpectCt, ExpectStaple, Fingerprint, Hpkp, LenientString, Level, LogEntry, Measurements, Metrics, - RelayInfo, Request, Span, Stacktrace, Tags, TemplateInfo, Thread, Timestamp, User, Values, + RelayInfo, Request, Span, Stacktrace, Tags, TemplateInfo, Thread, Timestamp, TransactionInfo, + User, Values, }; use crate::types::{ Annotated, Array, Empty, ErrorKind, FromValue, IntoValue, Object, SkipSerialization, Value, @@ -255,6 +256,10 @@ pub struct Event { #[metastructure(max_chars = "culprit", trim_whitespace = "true")] pub transaction: Annotated, + /// Additional information about the name of the transaction. + #[metastructure(skip_serialization = "empty")] + pub transaction_info: Annotated, + /// Time since the start of the transaction until the error occurred. pub time_spent: Annotated, diff --git a/relay-general/src/protocol/mod.rs b/relay-general/src/protocol/mod.rs index e61a6080386..2520ac1788b 100644 --- a/relay-general/src/protocol/mod.rs +++ b/relay-general/src/protocol/mod.rs @@ -25,6 +25,7 @@ mod stacktrace; mod tags; mod templateinfo; mod thread; +mod transaction; mod types; mod user; mod user_report; @@ -68,6 +69,7 @@ pub use self::stacktrace::{Frame, FrameData, FrameVars, RawStacktrace, Stacktrac pub use self::tags::{TagEntry, Tags}; pub use self::templateinfo::TemplateInfo; pub use self::thread::{Thread, ThreadId}; +pub use self::transaction::TransactionInfo; pub use self::types::{ datetime_to_timestamp, Addr, AsPair, InvalidRegVal, IpAddr, JsonLenientString, LenientString, Level, PairList, ParseLevelError, RegVal, Timestamp, Values, diff --git a/relay-general/src/protocol/transaction.rs b/relay-general/src/protocol/transaction.rs new file mode 100644 index 00000000000..f7b130b65a9 --- /dev/null +++ b/relay-general/src/protocol/transaction.rs @@ -0,0 +1,169 @@ +use std::fmt; +use std::str::FromStr; + +use crate::processor::ProcessValue; +use crate::types::{Annotated, Empty, ErrorKind, FromValue, IntoValue, SkipSerialization, Value}; + +/// Describes how the name of the transaction was determined. +#[derive(Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] +#[schemars(rename_all = "kebab-case")] +pub enum TransactionSource { + /// User-defined name set through `set_transaction_name`. + Custom, + /// Raw URL, potentially containing identifiers. + Url, + /// The SDK is configured to send a [`route`](Self::Route), but has to fall back to a raw URL + /// for this particular transaction. + UrlFallback, + /// Parametrized URL or route. + Route, + /// Name of the view handling the request. + View, + /// Named after a software component, such as a function or class name. + Component, + /// Name of a background task (e.g. a Celery task). + Task, + /// This is the default value set by Relay for legacy SDKs. + Unknown, + /// Any other unknown source that is not explicitly defined above. + Other(String), +} + +impl FromStr for TransactionSource { + type Err = std::convert::Infallible; + + fn from_str(s: &str) -> Result { + match s { + "custom" => Ok(Self::Custom), + "url" => Ok(Self::Url), + "url-fallback" => Ok(Self::UrlFallback), + "route" => Ok(Self::Route), + "view" => Ok(Self::View), + "component" => Ok(Self::Component), + "task" => Ok(Self::Task), + "unknown" => Ok(Self::Unknown), + s => Ok(Self::Other(s.to_owned())), + } + } +} + +impl fmt::Display for TransactionSource { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Custom => write!(f, "custom"), + Self::Url => write!(f, "url"), + Self::UrlFallback => write!(f, "url-fallback"), + Self::Route => write!(f, "route"), + Self::View => write!(f, "view"), + Self::Component => write!(f, "component"), + Self::Task => write!(f, "task"), + Self::Unknown => write!(f, "unknown"), + Self::Other(s) => write!(f, "{}", s), + } + } +} + +impl Default for TransactionSource { + fn default() -> Self { + Self::Unknown + } +} + +impl Empty for TransactionSource { + #[inline] + fn is_empty(&self) -> bool { + matches!(self, Self::Unknown) + } +} + +impl FromValue for TransactionSource { + fn from_value(value: Annotated) -> Annotated { + match String::from_value(value) { + Annotated(Some(value), mut meta) => match value.parse() { + Ok(source) => Annotated(Some(source), meta), + Err(_) => { + meta.add_error(ErrorKind::InvalidData); + meta.set_original_value(Some(value)); + Annotated(None, meta) + } + }, + Annotated(None, meta) => Annotated(None, meta), + } + } +} + +impl IntoValue for TransactionSource { + fn into_value(self) -> Value + where + Self: Sized, + { + Value::String(self.to_string()) + } + + fn serialize_payload(&self, s: S, _behavior: SkipSerialization) -> Result + where + Self: Sized, + S: serde::Serializer, + { + serde::Serialize::serialize(&self.to_string(), s) + } +} + +impl ProcessValue for TransactionSource {} + +/// Additional information about the name of the transaction. +#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)] +#[cfg_attr(feature = "jsonschema", derive(JsonSchema))] +pub struct TransactionInfo { + /// Describes how the name of the transaction was determined. + /// + /// This will be used by the server to decide whether or not to scrub identifiers from the + /// transaction name, or replace the entire name with a placeholder. + pub source: Annotated, + + /// The unmodified transaction name as obtained by the source. + /// + /// This value will only be set if the transaction name was modified during event processing. + #[metastructure(max_chars = "culprit", trim_whitespace = "true")] + pub original: Annotated, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_url_fallback_roundtrip() { + let json = r#""url-fallback""#; + let source = Annotated::new(TransactionSource::UrlFallback); + + assert_eq_dbg!(source, Annotated::from_json(json).unwrap()); + assert_eq_str!(json, source.payload_to_json_pretty().unwrap()); + } + + #[test] + fn test_other_source_roundtrip() { + let json = r#""something-new""#; + let source = Annotated::new(TransactionSource::Other("something-new".to_owned())); + + assert_eq_dbg!(source, Annotated::from_json(json).unwrap()); + assert_eq_str!(json, source.payload_to_json_pretty().unwrap()); + } + + #[test] + fn test_transaction_info_roundtrip() { + let json = r#"{ + "source": "url", + "original": "/auth/login/john123/" +}"#; + + let info = Annotated::new(TransactionInfo { + source: Annotated::new(TransactionSource::Url), + original: Annotated::new("/auth/login/john123/".to_owned()), + }); + + assert_eq_dbg!(info, Annotated::from_json(json).unwrap()); + assert_eq_str!(json, info.to_json_pretty().unwrap()); + } +} diff --git a/relay-general/tests/snapshots/test_fixtures__event_schema.snap b/relay-general/tests/snapshots/test_fixtures__event_schema.snap index 122693084e4..237fe4a4550 100644 --- a/relay-general/tests/snapshots/test_fixtures__event_schema.snap +++ b/relay-general/tests/snapshots/test_fixtures__event_schema.snap @@ -1,5 +1,6 @@ --- source: relay-general/tests/test_fixtures.rs +assertion_line: 106 expression: event_json_schema() --- { @@ -347,6 +348,18 @@ expression: event_json_schema() "null" ] }, + "transaction_info": { + "description": " Additional information about the name of the transaction.", + "default": null, + "anyOf": [ + { + "$ref": "#/definitions/TransactionInfo" + }, + { + "type": "null" + } + ] + }, "type": { "description": " Type of the event. Defaults to `default`.\n\n The event type determines how Sentry handles the event and has an impact on processing, rate\n limiting, and quotas. There are three fundamental classes of event types:\n\n - **Error monitoring events**: Processed and grouped into unique issues based on their\n exception stack traces and error messages.\n - **Security events**: Derived from Browser security violation reports and grouped into\n unique issues based on the endpoint and violation. SDKs do not send such events.\n - **Transaction events** (`transaction`): Contain operation spans and collected into traces\n for performance monitoring.\n\n Transactions must explicitly specify the `\"transaction\"` event type. In all other cases,\n Sentry infers the appropriate event type from the payload and overrides the stated type.\n SDKs should not send an event type other than for transactions.\n\n Example:\n\n ```json\n {\n \"type\": \"transaction\",\n \"spans\": []\n }\n ```", "default": null, @@ -2803,6 +2816,68 @@ expression: event_json_schema() } ] }, + "TransactionInfo": { + "description": " Additional information about the name of the transaction.", + "anyOf": [ + { + "type": "object", + "properties": { + "original": { + "description": " The unmodified transaction name as obtained by the source.\n\n This value will only be set if the transaction name was modified during event processing.", + "default": null, + "type": [ + "string", + "null" + ] + }, + "source": { + "description": " Describes how the name of the transaction was determined.\n\n This will be used by the server to decide whether or not to scrub identifiers from the\n transaction name, or replace the entire name with a placeholder.", + "default": null, + "anyOf": [ + { + "$ref": "#/definitions/TransactionSource" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + } + ] + }, + "TransactionSource": { + "description": "Describes how the name of the transaction was determined.", + "oneOf": [ + { + "type": "string", + "enum": [ + "custom", + "url", + "url-fallback", + "route", + "view", + "component", + "task", + "unknown" + ] + }, + { + "description": "Any other unknown source that is not explicitly defined above.", + "type": "object", + "required": [ + "other" + ], + "properties": { + "other": { + "type": "string" + } + }, + "additionalProperties": false + } + ] + }, "User": { "description": " Information about the user who triggered an event.\n\n ```json\n {\n \"user\": {\n \"id\": \"unique_id\",\n \"username\": \"my_user\",\n \"email\": \"foo@example.com\",\n \"ip_address\": \"127.0.0.1\",\n \"subscription\": \"basic\"\n }\n }\n ```", "anyOf": [ From 47bde73e3821e6b0ad87802cea4e255591d9c324 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Fri, 1 Jul 2022 13:50:37 +0200 Subject: [PATCH 2/7] meta: Changelog --- CHANGELOG.md | 2 +- py/CHANGELOG.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0066a589065..29a1f7e3b6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ **Features**: - Extract metrics also from trace-sampled transactions. ([#1317](https://github.com/getsentry/relay/pull/1317)) - +- Support `transaction_info` on event payloads. ([#1330](https://github.com/getsentry/relay/pull/1330)) **Bug Fixes**: diff --git a/py/CHANGELOG.md b/py/CHANGELOG.md index e1798c09261..2f3955942e0 100644 --- a/py/CHANGELOG.md +++ b/py/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add `transaction_info` to event payloads, including the transaction's source and internal original transaction name. ([#1330](https://github.com/getsentry/relay/pull/1330)) + ## 0.8.13 - Add a data category constant for Replays. ([#1239](https://github.com/getsentry/relay/pull/1239)) From 07ce6220b70dbd83c9545e5788b6d308e49d4b60 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Fri, 1 Jul 2022 14:12:13 +0200 Subject: [PATCH 3/7] ref: Fix JSON schema --- relay-general/src/protocol/transaction.rs | 1 + .../test_fixtures__event_schema.snap | 37 +++++-------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/relay-general/src/protocol/transaction.rs b/relay-general/src/protocol/transaction.rs index f7b130b65a9..1a72341a7e1 100644 --- a/relay-general/src/protocol/transaction.rs +++ b/relay-general/src/protocol/transaction.rs @@ -27,6 +27,7 @@ pub enum TransactionSource { /// This is the default value set by Relay for legacy SDKs. Unknown, /// Any other unknown source that is not explicitly defined above. + #[schemars(skip)] Other(String), } diff --git a/relay-general/tests/snapshots/test_fixtures__event_schema.snap b/relay-general/tests/snapshots/test_fixtures__event_schema.snap index 237fe4a4550..06089a6d908 100644 --- a/relay-general/tests/snapshots/test_fixtures__event_schema.snap +++ b/relay-general/tests/snapshots/test_fixtures__event_schema.snap @@ -2849,33 +2849,16 @@ expression: event_json_schema() }, "TransactionSource": { "description": "Describes how the name of the transaction was determined.", - "oneOf": [ - { - "type": "string", - "enum": [ - "custom", - "url", - "url-fallback", - "route", - "view", - "component", - "task", - "unknown" - ] - }, - { - "description": "Any other unknown source that is not explicitly defined above.", - "type": "object", - "required": [ - "other" - ], - "properties": { - "other": { - "type": "string" - } - }, - "additionalProperties": false - } + "type": "string", + "enum": [ + "custom", + "url", + "url-fallback", + "route", + "view", + "component", + "task", + "unknown" ] }, "User": { From 564071ea156589093d53b7597624e54555190c38 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Fri, 1 Jul 2022 14:20:55 +0200 Subject: [PATCH 4/7] ref: Remove fallback variant --- relay-general/src/protocol/transaction.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/relay-general/src/protocol/transaction.rs b/relay-general/src/protocol/transaction.rs index 1a72341a7e1..16485c377cb 100644 --- a/relay-general/src/protocol/transaction.rs +++ b/relay-general/src/protocol/transaction.rs @@ -13,9 +13,6 @@ pub enum TransactionSource { Custom, /// Raw URL, potentially containing identifiers. Url, - /// The SDK is configured to send a [`route`](Self::Route), but has to fall back to a raw URL - /// for this particular transaction. - UrlFallback, /// Parametrized URL or route. Route, /// Name of the view handling the request. @@ -38,7 +35,6 @@ impl FromStr for TransactionSource { match s { "custom" => Ok(Self::Custom), "url" => Ok(Self::Url), - "url-fallback" => Ok(Self::UrlFallback), "route" => Ok(Self::Route), "view" => Ok(Self::View), "component" => Ok(Self::Component), @@ -54,7 +50,6 @@ impl fmt::Display for TransactionSource { match self { Self::Custom => write!(f, "custom"), Self::Url => write!(f, "url"), - Self::UrlFallback => write!(f, "url-fallback"), Self::Route => write!(f, "route"), Self::View => write!(f, "view"), Self::Component => write!(f, "component"), @@ -134,15 +129,6 @@ pub struct TransactionInfo { mod tests { use super::*; - #[test] - fn test_url_fallback_roundtrip() { - let json = r#""url-fallback""#; - let source = Annotated::new(TransactionSource::UrlFallback); - - assert_eq_dbg!(source, Annotated::from_json(json).unwrap()); - assert_eq_str!(json, source.payload_to_json_pretty().unwrap()); - } - #[test] fn test_other_source_roundtrip() { let json = r#""something-new""#; From 2c24a6fa997d8fff0613d05ed8adb10e5b966ed2 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Mon, 4 Jul 2022 09:17:30 +0200 Subject: [PATCH 5/7] feat(server): Log a metric for transaction sources --- relay-general/src/protocol/mod.rs | 2 +- relay-server/src/actors/envelopes.rs | 14 ++++++++++++++ relay-server/src/statsd.rs | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/relay-general/src/protocol/mod.rs b/relay-general/src/protocol/mod.rs index 2520ac1788b..d5edff939f3 100644 --- a/relay-general/src/protocol/mod.rs +++ b/relay-general/src/protocol/mod.rs @@ -69,7 +69,7 @@ pub use self::stacktrace::{Frame, FrameData, FrameVars, RawStacktrace, Stacktrac pub use self::tags::{TagEntry, Tags}; pub use self::templateinfo::TemplateInfo; pub use self::thread::{Thread, ThreadId}; -pub use self::transaction::TransactionInfo; +pub use self::transaction::{TransactionInfo, TransactionSource}; pub use self::types::{ datetime_to_timestamp, Addr, AsPair, InvalidRegVal, IpAddr, JsonLenientString, LenientString, Level, PairList, ParseLevelError, RegVal, Timestamp, Values, diff --git a/relay-server/src/actors/envelopes.rs b/relay-server/src/actors/envelopes.rs index ddae7a3dda9..c2278b57718 100644 --- a/relay-server/src/actors/envelopes.rs +++ b/relay-server/src/actors/envelopes.rs @@ -66,6 +66,7 @@ use { crate::service::ServerErrorKind, crate::utils::{EnvelopeLimiter, ErrorBoundary}, failure::ResultExt, + relay_general::protocol::TransactionSource, relay_general::store::{GeoIpLookup, StoreConfig, StoreProcessor}, relay_quotas::{RateLimitingError, RedisRateLimiter}, symbolic_unreal::{Unreal4Error, Unreal4ErrorKind}, @@ -1520,6 +1521,19 @@ impl EnvelopeProcessor { } event._metrics = Annotated::new(metrics); + + if event.ty.value() == Some(&EventType::Transaction) { + let source = event + .transaction_info + .value() + .and_then(|info| info.source.value()) + .unwrap_or(&TransactionSource::Unknown); + + metric!( + counter(RelayCounters::EventTransactionSource) += 1, + source = &source.to_string() + ); + } } // TODO: Temporary workaround before processing. Experimental SDKs relied on a buggy diff --git a/relay-server/src/statsd.rs b/relay-server/src/statsd.rs index fce36f6f597..50515876acf 100644 --- a/relay-server/src/statsd.rs +++ b/relay-server/src/statsd.rs @@ -447,6 +447,14 @@ pub enum RelayCounters { /// This metric is tagged with: /// - `version`: The event protocol version number defaulting to `7`. EventProtocol, + /// The number of transaction events processed by the source of the transaction name. + /// + /// This metric is tagged with: + /// - `source`: The source of the transaction name on the client. See the [transaction source + /// documentation](https://develop.sentry.dev/sdk/event-payloads/properties/transaction_info/) + /// for all valid values. + #[cfg(feature = "processing")] + EventTransactionSource, /// Number of HTTP requests reaching Relay. Requests, /// Number of completed HTTP requests. @@ -496,6 +504,7 @@ impl CounterMetric for RelayCounters { #[cfg(feature = "processing")] RelayCounters::ProcessingProduceError => "processing.produce.error", RelayCounters::EventProtocol => "event.protocol", + RelayCounters::EventTransactionSource => "event.transaction_source", RelayCounters::Requests => "requests", RelayCounters::ResponsesStatusCodes => "responses.status_codes", RelayCounters::EvictingStaleProjectCaches => "project_cache.eviction", From dab1d3e2ce1f7bca6741827a5e997c8774a9f8b5 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Mon, 4 Jul 2022 09:21:00 +0200 Subject: [PATCH 6/7] fix: Feature flagging --- relay-general/src/protocol/transaction.rs | 4 ++-- .../tests/snapshots/test_fixtures__event_schema.snap | 1 - relay-server/src/actors/envelopes.rs | 3 +-- relay-server/src/statsd.rs | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/relay-general/src/protocol/transaction.rs b/relay-general/src/protocol/transaction.rs index 2f8f897b06c..124bd290cd2 100644 --- a/relay-general/src/protocol/transaction.rs +++ b/relay-general/src/protocol/transaction.rs @@ -7,7 +7,7 @@ use crate::types::{Annotated, Empty, ErrorKind, FromValue, IntoValue, SkipSerial /// Describes how the name of the transaction was determined. #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] -#[schemars(rename_all = "kebab-case")] +#[cfg_attr(feature = "jsonschema", schemars(rename_all = "kebab-case"))] pub enum TransactionSource { /// User-defined name set through `set_transaction_name`. Custom, @@ -24,7 +24,7 @@ pub enum TransactionSource { /// This is the default value set by Relay for legacy SDKs. Unknown, /// Any other unknown source that is not explicitly defined above. - #[schemars(skip)] + #[cfg_attr(feature = "jsonschema", schemars(skip))] Other(String), } diff --git a/relay-general/tests/snapshots/test_fixtures__event_schema.snap b/relay-general/tests/snapshots/test_fixtures__event_schema.snap index 06089a6d908..f7645de1f75 100644 --- a/relay-general/tests/snapshots/test_fixtures__event_schema.snap +++ b/relay-general/tests/snapshots/test_fixtures__event_schema.snap @@ -2853,7 +2853,6 @@ expression: event_json_schema() "enum": [ "custom", "url", - "url-fallback", "route", "view", "component", diff --git a/relay-server/src/actors/envelopes.rs b/relay-server/src/actors/envelopes.rs index c2278b57718..a502468673e 100644 --- a/relay-server/src/actors/envelopes.rs +++ b/relay-server/src/actors/envelopes.rs @@ -29,7 +29,7 @@ use relay_general::processor::{process_value, ProcessingState}; use relay_general::protocol::{ self, Breadcrumb, ClientReport, Csp, Event, EventId, EventType, ExpectCt, ExpectStaple, Hpkp, IpAddr, LenientString, Metrics, RelayInfo, SecurityReportType, SessionAggregates, - SessionAttributes, SessionUpdate, Timestamp, UserReport, Values, + SessionAttributes, SessionUpdate, Timestamp, TransactionSource, UserReport, Values, }; use relay_general::store::ClockDriftProcessor; use relay_general::types::{Annotated, Array, FromValue, Object, ProcessingAction, Value}; @@ -66,7 +66,6 @@ use { crate::service::ServerErrorKind, crate::utils::{EnvelopeLimiter, ErrorBoundary}, failure::ResultExt, - relay_general::protocol::TransactionSource, relay_general::store::{GeoIpLookup, StoreConfig, StoreProcessor}, relay_quotas::{RateLimitingError, RedisRateLimiter}, symbolic_unreal::{Unreal4Error, Unreal4ErrorKind}, diff --git a/relay-server/src/statsd.rs b/relay-server/src/statsd.rs index 50515876acf..93261533e0b 100644 --- a/relay-server/src/statsd.rs +++ b/relay-server/src/statsd.rs @@ -453,7 +453,6 @@ pub enum RelayCounters { /// - `source`: The source of the transaction name on the client. See the [transaction source /// documentation](https://develop.sentry.dev/sdk/event-payloads/properties/transaction_info/) /// for all valid values. - #[cfg(feature = "processing")] EventTransactionSource, /// Number of HTTP requests reaching Relay. Requests, From fdc51c9f64ed8e3d06017ad9243a73f7444600c8 Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Mon, 4 Jul 2022 10:34:21 +0200 Subject: [PATCH 7/7] feat(server): More metric tags --- relay-server/src/actors/envelopes.rs | 4 +++- relay-server/src/extractors/request_meta.rs | 11 +++++++++++ relay-server/src/statsd.rs | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/relay-server/src/actors/envelopes.rs b/relay-server/src/actors/envelopes.rs index a502468673e..aa951982450 100644 --- a/relay-server/src/actors/envelopes.rs +++ b/relay-server/src/actors/envelopes.rs @@ -1530,7 +1530,9 @@ impl EnvelopeProcessor { metric!( counter(RelayCounters::EventTransactionSource) += 1, - source = &source.to_string() + source = &source.to_string(), + sdk = envelope.meta().client_name().unwrap_or("proprietary"), + platform = event.platform.as_str().unwrap_or("other"), ); } } diff --git a/relay-server/src/extractors/request_meta.rs b/relay-server/src/extractors/request_meta.rs index a2581bca9da..d3ed121599b 100644 --- a/relay-server/src/extractors/request_meta.rs +++ b/relay-server/src/extractors/request_meta.rs @@ -204,10 +204,21 @@ pub struct RequestMeta { impl RequestMeta { /// Returns the client that sent this event (Sentry SDK identifier). + /// + /// The client is formatted as `"sdk/version"`, for example `"raven-node/2.6.3"`. pub fn client(&self) -> Option<&str> { self.client.as_deref() } + /// Returns the name of the client that sent the event without version. + /// + /// If the client is not sent in standard format, this method returns `None`. + pub fn client_name(&self) -> Option<&str> { + let client = self.client()?; + let (name, _version) = client.split_once('/')?; + Some(name) + } + /// Returns the protocol version of the event payload. pub fn version(&self) -> u16 { self.version diff --git a/relay-server/src/statsd.rs b/relay-server/src/statsd.rs index 93261533e0b..3a59e18b3ab 100644 --- a/relay-server/src/statsd.rs +++ b/relay-server/src/statsd.rs @@ -450,6 +450,9 @@ pub enum RelayCounters { /// The number of transaction events processed by the source of the transaction name. /// /// This metric is tagged with: + /// - `platform`: The event's platform, such as `"javascript"`. + /// - `sdk`: The name of the Sentry SDK sending the transaction. This tag is only set for + /// Sentry's SDKs and defaults to "proprietary". /// - `source`: The source of the transaction name on the client. See the [transaction source /// documentation](https://develop.sentry.dev/sdk/event-payloads/properties/transaction_info/) /// for all valid values.