Skip to content

Commit

Permalink
feat(on-demand): Add new contexts to the Event getter (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
iambriccardo authored Nov 12, 2024
1 parent a943af7 commit 9caea29
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Use `DateTime<Utc>` instead of `Instant` for tracking the received time of the `Envelope`. ([#4184](https://github.com/getsentry/relay/pull/4184))
- Add a field to suggest consumers to ingest spans in EAP. ([#4206](https://github.com/getsentry/relay/pull/4206))
- Run internal worker threads with a lower priority. ([#4222](https://github.com/getsentry/relay/pull/4222))
- Add additional fields to the `Event` `Getter`. ([#4238](https://github.com/getsentry/relay/pull/4238))

## 24.10.0

Expand Down
45 changes: 41 additions & 4 deletions relay-event-schema/src/protocol/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use uuid::Uuid;
use crate::processor::ProcessValue;
use crate::protocol::{
AppContext, Breadcrumb, Breakdowns, BrowserContext, ClientSdkInfo, Contexts, Csp, DebugMeta,
DefaultContext, DeviceContext, EventType, Exception, ExpectCt, ExpectStaple, Fingerprint, Hpkp,
LenientString, Level, LogEntry, Measurements, Metrics, MetricsSummary, OsContext,
ProfileContext, RelayInfo, Request, ResponseContext, Span, SpanId, Stacktrace, Tags,
TemplateInfo, Thread, Timestamp, TraceContext, TransactionInfo, User, Values,
DefaultContext, DeviceContext, EventType, Exception, ExpectCt, ExpectStaple, Fingerprint,
GpuContext, Hpkp, LenientString, Level, LogEntry, Measurements, Metrics, MetricsSummary,
MonitorContext, OsContext, ProfileContext, RelayInfo, Request, ResponseContext, RuntimeContext,
Span, SpanId, Stacktrace, Tags, TemplateInfo, Thread, Timestamp, TraceContext, TransactionInfo,
User, Values,
};

/// Wrapper around a UUID with slightly different formatting.
Expand Down Expand Up @@ -674,6 +675,11 @@ impl Getter for Event {
"contexts.app.in_foreground" => {
self.context::<AppContext>()?.in_foreground.value()?.into()
}
"contexts.app.device_app_hash" => self
.context::<AppContext>()?
.device_app_hash
.as_str()?
.into(),
"contexts.device.arch" => self.context::<DeviceContext>()?.arch.as_str()?.into(),
"contexts.device.battery_level" => self
.context::<DeviceContext>()?
Expand Down Expand Up @@ -713,12 +719,23 @@ impl Getter for Event {
"contexts.device.simulator" => {
self.context::<DeviceContext>()?.simulator.value()?.into()
}
"contexts.gpu.vendor_name" => {
self.context::<GpuContext>()?.vendor_name.as_str()?.into()
}
"contexts.gpu.name" => self.context::<GpuContext>()?.name.as_str()?.into(),
"contexts.monitor.id" => self.context::<MonitorContext>()?.get("id")?.value()?.into(),
"contexts.monitor.slug" => self
.context::<MonitorContext>()?
.get("slug")?
.value()?
.into(),
"contexts.os.build" => self.context::<OsContext>()?.build.as_str()?.into(),
"contexts.os.kernel_version" => {
self.context::<OsContext>()?.kernel_version.as_str()?.into()
}
"contexts.os.name" => self.context::<OsContext>()?.name.as_str()?.into(),
"contexts.os.version" => self.context::<OsContext>()?.version.as_str()?.into(),
"contexts.os.rooted" => self.context::<OsContext>()?.rooted.value()?.into(),
"contexts.browser.name" => self.context::<BrowserContext>()?.name.as_str()?.into(),
"contexts.browser.version" => {
self.context::<BrowserContext>()?.version.as_str()?.into()
Expand Down Expand Up @@ -746,6 +763,7 @@ impl Getter for Event {
super::Context::Other(context) => context.get("crash_type")?.value()?.into(),
_ => return None,
},
"contexts.runtime.name" => self.context::<RuntimeContext>()?.name.as_str()?.into(),

// Computed fields (see Discover)
"duration" => {
Expand Down Expand Up @@ -807,6 +825,7 @@ mod tests {
use chrono::{TimeZone, Utc};
use relay_protocol::{ErrorKind, Map, Meta};
use similar_asserts::assert_eq;
use std::collections::BTreeMap;
use uuid::uuid;

use super::*;
Expand Down Expand Up @@ -1158,6 +1177,16 @@ mod tests {
))),
..ProfileContext::default()
});
let mut monitor_context_fields = BTreeMap::new();
monitor_context_fields.insert(
"id".to_string(),
Annotated::new(Value::String("123".to_string())),
);
monitor_context_fields.insert(
"slug".to_string(),
Annotated::new(Value::String("my_monitor".to_string())),
);
contexts.add(MonitorContext(monitor_context_fields));
contexts
}),
..Default::default()
Expand Down Expand Up @@ -1272,6 +1301,14 @@ mod tests {
Some(Val::String("message")),
event.get_value("event.logentry.message")
);
assert_eq!(
Some(Val::String("123")),
event.get_value("event.contexts.monitor.id")
);
assert_eq!(
Some(Val::String("my_monitor")),
event.get_value("event.contexts.monitor.slug")
);
}

#[test]
Expand Down

0 comments on commit 9caea29

Please sign in to comment.