Skip to content

Commit 726be3f

Browse files
authored
ref(server): introduce client name enum (#4226)
Introduces an enum which allows us to have more fine grained control over which sdks are tagged
1 parent d23c39a commit 726be3f

File tree

4 files changed

+93
-15
lines changed

4 files changed

+93
-15
lines changed

relay-server/src/endpoints/common.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,12 @@ pub async fn handle_envelope(
334334
state: &ServiceState,
335335
envelope: Box<Envelope>,
336336
) -> Result<Option<EventId>, BadStoreRequest> {
337-
let client_name = envelope
338-
.meta()
339-
.client_name()
340-
.filter(|name| name.starts_with("sentry") || name.starts_with("raven"))
341-
.unwrap_or("proprietary");
337+
let client_name = envelope.meta().client_name();
342338
for item in envelope.items() {
343339
metric!(
344340
histogram(RelayHistograms::EnvelopeItemSize) = item.payload().len() as u64,
345341
item_type = item.ty().name(),
346-
sdk = client_name,
342+
sdk = client_name.name(),
347343
)
348344
}
349345

relay-server/src/extractors/request_meta.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use url::Url;
2323

2424
use crate::extractors::{ForwardedFor, ReceivedAt};
2525
use crate::service::ServiceState;
26-
use crate::statsd::RelayCounters;
26+
use crate::statsd::{ClientName, RelayCounters};
2727
use crate::utils::ApiErrorResponse;
2828

2929
#[derive(Debug, thiserror::Error)]
@@ -248,10 +248,11 @@ impl<D> RequestMeta<D> {
248248
/// Returns the name of the client that sent the event without version.
249249
///
250250
/// If the client is not sent in standard format, this method returns `None`.
251-
pub fn client_name(&self) -> Option<&str> {
252-
let client = self.client()?;
253-
let (name, _version) = client.split_once('/')?;
254-
Some(name)
251+
pub fn client_name(&self) -> ClientName {
252+
self.client()
253+
.and_then(|client| client.split_once('/'))
254+
.map(|(client, _)| client)
255+
.map_or(ClientName::Other("proprietary"), ClientName::from)
255256
}
256257

257258
/// Returns the protocol version of the event payload.

relay-server/src/services/processor/event.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub fn finalize<G: EventProcessing>(
192192
metric!(
193193
counter(RelayCounters::EventTransaction) += 1,
194194
source = utils::transaction_source_tag(event),
195-
platform = PlatformTag::from(event.platform.as_str().unwrap_or("other")).as_str(),
195+
platform = PlatformTag::from(event.platform.as_str().unwrap_or("other")).name(),
196196
contains_slashes = if event.transaction.as_str().unwrap_or_default().contains('/') {
197197
"true"
198198
} else {
@@ -203,7 +203,7 @@ pub fn finalize<G: EventProcessing>(
203203
let span_count = event.spans.value().map(Vec::len).unwrap_or(0) as u64;
204204
metric!(
205205
histogram(RelayHistograms::EventSpans) = span_count,
206-
sdk = envelope.meta().client_name().unwrap_or("proprietary"),
206+
sdk = envelope.meta().client_name().name(),
207207
platform = event.platform.as_str().unwrap_or("other"),
208208
);
209209

@@ -215,7 +215,7 @@ pub fn finalize<G: EventProcessing>(
215215
if has_otel {
216216
metric!(
217217
counter(RelayCounters::OpenTelemetryEvent) += 1,
218-
sdk = envelope.meta().client_name().unwrap_or("proprietary"),
218+
sdk = envelope.meta().client_name().name(),
219219
platform = event.platform.as_str().unwrap_or("other"),
220220
);
221221
}

relay-server/src/statsd.rs

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ pub enum PlatformTag {
935935
}
936936

937937
impl PlatformTag {
938-
pub fn as_str(&self) -> &str {
938+
pub fn name(&self) -> &str {
939939
match self {
940940
Self::Cocoa => "cocoa",
941941
Self::Csharp => "csharp",
@@ -979,3 +979,84 @@ impl<S: AsRef<str>> From<S> for PlatformTag {
979979
}
980980
}
981981
}
982+
983+
/// Low-cardinality SDK name that can be used as a statsd tag.
984+
pub enum ClientName<'a> {
985+
Ruby,
986+
CocoaFlutter,
987+
CocoaReactNative,
988+
Cocoa,
989+
Dotnet,
990+
AndroidReactNative,
991+
AndroidJava,
992+
SpringBoot,
993+
JavascriptBrowser,
994+
Electron,
995+
NestJs,
996+
NextJs,
997+
Node,
998+
React,
999+
Vue,
1000+
Native,
1001+
Laravel,
1002+
Symfony,
1003+
Php,
1004+
Python,
1005+
Other(&'a str),
1006+
}
1007+
1008+
impl<'a> ClientName<'a> {
1009+
pub fn name(&self) -> &'static str {
1010+
match self {
1011+
Self::Ruby => "sentry-ruby",
1012+
Self::CocoaFlutter => "sentry.cocoa.flutter",
1013+
Self::CocoaReactNative => "sentry.cocoa.react-native",
1014+
Self::Cocoa => "sentry.cocoa",
1015+
Self::Dotnet => "sentry.dotnet",
1016+
Self::AndroidReactNative => "sentry.java.android.react-native",
1017+
Self::AndroidJava => "sentry.java.android",
1018+
Self::SpringBoot => "sentry.java.spring-boot.jakarta",
1019+
Self::JavascriptBrowser => "sentry.javascript.browser",
1020+
Self::Electron => "sentry.javascript.electron",
1021+
Self::NestJs => "sentry.javascript.nestjs",
1022+
Self::NextJs => "sentry.javascript.nextjs",
1023+
Self::Node => "sentry.javascript.node",
1024+
Self::React => "sentry.javascript.react",
1025+
Self::Vue => "sentry.javascript.vue",
1026+
Self::Native => "sentry.native",
1027+
Self::Laravel => "sentry.php.laravel",
1028+
Self::Symfony => "sentry.php.symfony",
1029+
Self::Php => "sentry.php",
1030+
Self::Python => "sentry.python",
1031+
Self::Other(_) => "other",
1032+
}
1033+
}
1034+
}
1035+
1036+
impl<'a> From<&'a str> for ClientName<'a> {
1037+
fn from(value: &'a str) -> Self {
1038+
match value {
1039+
"sentry-ruby" => Self::Ruby,
1040+
"sentry.cocoa.flutter" => Self::CocoaFlutter,
1041+
"sentry.cocoa.react-native" => Self::CocoaReactNative,
1042+
"sentry.cocoa" => Self::Cocoa,
1043+
"sentry.dotnet" => Self::Dotnet,
1044+
"sentry.java.android.react-native" => Self::AndroidReactNative,
1045+
"sentry.java.android" => Self::AndroidJava,
1046+
"sentry.java.spring-boot.jakarta" => Self::SpringBoot,
1047+
"sentry.javascript.browser" => Self::JavascriptBrowser,
1048+
"sentry.javascript.electron" => Self::Electron,
1049+
"sentry.javascript.nestjs" => Self::NestJs,
1050+
"sentry.javascript.nextjs" => Self::NextJs,
1051+
"sentry.javascript.node" => Self::Node,
1052+
"sentry.javascript.react" => Self::React,
1053+
"sentry.javascript.vue" => Self::Vue,
1054+
"sentry.native" => Self::Native,
1055+
"sentry.php.laravel" => Self::Laravel,
1056+
"sentry.php.symfony" => Self::Symfony,
1057+
"sentry.php" => Self::Php,
1058+
"sentry.python" => Self::Python,
1059+
other => Self::Other(other),
1060+
}
1061+
}
1062+
}

0 commit comments

Comments
 (0)