Skip to content

Commit

Permalink
ref(server): introduce platform tag enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Litarnus committed Nov 6, 2024
1 parent 71ebf8a commit 5e62fe7
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 5 deletions.
9 changes: 4 additions & 5 deletions relay-server/src/endpoints/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::services::buffer::EnvelopeBuffer;
use crate::services::outcome::{DiscardReason, Outcome};
use crate::services::processor::{BucketSource, MetricData, ProcessMetrics, ProcessingGroup};
use crate::services::projects::cache::legacy::ValidateEnvelope;
use crate::statsd::{RelayCounters, RelayHistograms};
use crate::statsd::{RelayCounters, RelayHistograms, SdkTag};
use crate::utils::{self, ApiErrorResponse, FormDataIter, ManagedEnvelope};

#[derive(Clone, Copy, Debug, thiserror::Error)]
Expand Down Expand Up @@ -334,16 +334,15 @@ pub async fn handle_envelope(
state: &ServiceState,
envelope: Box<Envelope>,
) -> Result<Option<EventId>, BadStoreRequest> {
let client_name = envelope
let client_name: SdkTag = envelope
.meta()
.client_name()
.filter(|name| name.starts_with("sentry") || name.starts_with("raven"))
.unwrap_or("proprietary");
.map_or(SdkTag::Other, SdkTag::from);
for item in envelope.items() {
metric!(
histogram(RelayHistograms::EnvelopeItemSize) = item.payload().len() as u64,
item_type = item.ty().name(),
sdk = client_name,
sdk = client_name.as_str(),
)
}

Expand Down
80 changes: 80 additions & 0 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,83 @@ impl<S: AsRef<str>> From<S> for PlatformTag {
}
}
}

pub enum SdkTag {
Ruby,
CocoaFlutter,
CocoaReactNative,
Cocoa,
Dotnet,
AndroidReactNative,
AndroidJava,
SpringBoot,
JavascriptBrowser,
JavascriptElectron,
NestJs,
NextJS,
NodeJS,
React,
VueJS,
Native,
LaravelPHP,
SymfonyPHP,
PHP,
Python,
Other,
}

impl SdkTag {
pub fn as_str(&self) -> &str {
match self {
Self::Ruby => "sentry-ruby",
Self::CocoaFlutter => "sentry.cocoa.flutter",
Self::CocoaReactNative => "sentry.cocoa.react-native",
Self::Cocoa => "sentry.cocoa",
Self::Dotnet => "sentry.dotnet",
Self::AndroidReactNative => "sentry.java.android.react-native",
Self::AndroidJava => "sentry.java.android",
Self::SpringBoot => "sentry.java.spring-boot.jakarta",
Self::JavascriptBrowser => "sentry.javascript.browser",
Self::JavascriptElectron => "sentry.javascript.electron",
Self::NestJs => "sentry.javascript.nestjs",
Self::NextJS => "sentry.javascript.nextjs",
Self::NodeJS => "sentry.javascript.node",
Self::React => "sentry.javascript.react",
Self::VueJS => "sentry.javascript.vue",
Self::Native => "sentry.native",
Self::LaravelPHP => "sentry.php.laravel",
Self::SymfonyPHP => "sentry.php.symfony",
Self::PHP => "sentry.php",
Self::Python => "sentry.python",
Self::Other => "other",
}
}
}

impl<S: AsRef<str>> From<S> for SdkTag {
fn from(value: S) -> Self {
match value.as_ref() {
"sentry-ruby" => Self::Ruby,
"sentry.cocoa.flutter" => Self::CocoaFlutter,
"sentry.cocoa.react-native" => Self::CocoaReactNative,
"sentry.cocoa" => Self::Cocoa,
"sentry.dotnet" => Self::Dotnet,
"sentry.java.android.react-native" => Self::AndroidReactNative,
"sentry.java.android" => Self::AndroidJava,
"sentry.java.spring-boot.jakarta" => Self::SpringBoot,
"sentry.javascript.browser" => Self::JavascriptBrowser,
"sentry.javascript.electron" => Self::JavascriptElectron,
"sentry.javascript.nestjs" => Self::NestJs,
"sentry.javascript.nextjs" => Self::NextJS,
"sentry.javascript.node" => Self::NodeJS,
"sentry.javascript.react" => Self::React,
"sentry.javascript.vue" => Self::VueJS,
"sentry.native" => Self::Native,
"sentry.php.laravel" => Self::LaravelPHP,
"sentry.php.symfony" => Self::SymfonyPHP,
"sentry.php" => Self::PHP,
"sentry.python" => Self::Python,
_ => Self::Other,
}
}
}

0 comments on commit 5e62fe7

Please sign in to comment.