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(metrics): Support access to structured release fields #2276

Merged
merged 4 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
**Internal**:

- Implement basic generic metrics extraction for transaction events. ([#2252](https://github.com/getsentry/relay/pull/2252), [#2257](https://github.com/getsentry/relay/pull/2257))
- Support more fields in dynamic sampling, metric extraction, and conditional tagging. The added fields are `dist`, `user.{email,ip_address,name}`, `breakdowns.*`, and `extra.*`. ([#2259](https://github.com/getsentry/relay/pull/2259))
- Support more fields in dynamic sampling, metric extraction, and conditional tagging. The added fields are `dist`, `release.*`, `user.{email,ip_address,name}`, `breakdowns.*`, and `extra.*`. ([#2259](https://github.com/getsentry/relay/pull/2259), [#2276](https://github.com/getsentry/relay/pull/2276))

## 23.6.1

Expand Down
22 changes: 20 additions & 2 deletions relay-general/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,28 +538,39 @@ pub struct Event {
}

impl Event {
pub fn get_transaction_source(&self) -> &TransactionSource {
/// Returns the source of the transaction name if specified by the client.
///
/// See the [type docs](TransactionSource) for more information.
pub fn transaction_source(&self) -> &TransactionSource {
self.transaction_info
.value()
.and_then(|info| info.source.value())
.unwrap_or(&TransactionSource::Unknown)
}

pub fn get_tag_value(&self, tag_key: &str) -> Option<&str> {
/// Returns the value of a tag with the given key.
///
/// If tags are specified in a pair list and the tag is declared multiple times, this function
/// returns the first match.
pub fn tag_value(&self, tag_key: &str) -> Option<&str> {
if let Some(tags) = self.tags.value() {
tags.get(tag_key)
} else {
None
}
}

/// Returns `true` if [`modules`](Self::modules) contains the given module.
pub fn has_module(&self, module_name: &str) -> bool {
self.modules
.value()
.map(|m| m.contains_key(module_name))
.unwrap_or(false)
}

/// Return the identifier of the client SDK if available.
jan-auer marked this conversation as resolved.
Show resolved Hide resolved
///
/// Sentry's own SDKs use a naming schema prefixed with `sentry.`. Defaults to `"unknown"`.
pub fn sdk_name(&self) -> &str {
if let Some(client_sdk) = self.client_sdk.value() {
if let Some(name) = client_sdk.name.as_str() {
Expand All @@ -570,6 +581,9 @@ impl Event {
"unknown"
}

/// Return the version of the client SDK if available.
jan-auer marked this conversation as resolved.
Show resolved Hide resolved
///
/// Defaults to `"unknown"`.
pub fn sdk_version(&self) -> &str {
if let Some(client_sdk) = self.client_sdk.value() {
if let Some(version) = client_sdk.version.as_str() {
Expand Down Expand Up @@ -601,6 +615,10 @@ impl Event {

Some(value)
}

pub fn parse_release(&self) -> Option<crate::protocol::ParsedRelease> {
sentry_release_parser::Release::parse(self.release.as_str()?).ok()
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion relay-general/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod user;
mod user_report;
mod utils;

pub use sentry_release_parser::{validate_environment, validate_release};
pub use sentry_release_parser::{validate_environment, validate_release, Release as ParsedRelease};

pub use self::breadcrumb::*;
pub use self::breakdowns::*;
Expand Down
2 changes: 1 addition & 1 deletion relay-general/src/store/transactions/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub fn is_high_cardinality_sdk(event: &Event) -> bool {
return true;
}

let is_http_status_404 = event.get_tag_value("http.status_code") == Some("404");
let is_http_status_404 = event.tag_value("http.status_code") == Some("404");
if sdk_name == "sentry.python" && is_http_status_404 && client_sdk.has_integration("django") {
return true;
}
Expand Down
17 changes: 17 additions & 0 deletions relay-sampling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,23 @@ impl FieldValueProvider for Event {
}
_ => Value::Null,
},
"release.version.build" => self
.parse_release()
.as_ref()
.and_then(|r| r.version())
.and_then(|v| v.build_code())
.map_or(Value::Null, Value::from),
"release.package" => self
.parse_release()
.as_ref()
.and_then(|r| r.package())
.map_or(Value::Null, Value::from),
"release.version.short" => self
.parse_release()
.as_ref()
.and_then(|r| r.version())
.map(|v| v.raw_short())
.map_or(Value::Null, Value::from),

// Dynamic access to certain data bags
_ => {
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/metrics_extraction/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn get_transaction_name(
AcceptTransactionNames::ClientBased
) && !store::is_high_cardinality_sdk(event);

let source = event.get_transaction_source();
let source = event.transaction_source();
let use_original_name = is_low_cardinality(source, treat_unknown_as_low_cardinality);

let name_used;
Expand Down
2 changes: 1 addition & 1 deletion relay-server/src/metrics_extraction/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn http_status_code_from_span(span: &Span) -> Option<String> {
/// Extracts the HTTP status code.
pub(crate) fn extract_http_status_code(event: &Event) -> Option<String> {
// For SDKs which put the HTTP status code in the event tags.
if let Some(status_code) = event.get_tag_value("http.status_code") {
if let Some(status_code) = event.tag_value("http.status_code") {
return Some(status_code.to_owned());
}

Expand Down