Skip to content

Commit 9caea29

Browse files
authored
feat(on-demand): Add new contexts to the Event getter (#4238)
1 parent a943af7 commit 9caea29

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Use `DateTime<Utc>` instead of `Instant` for tracking the received time of the `Envelope`. ([#4184](https://github.com/getsentry/relay/pull/4184))
2727
- Add a field to suggest consumers to ingest spans in EAP. ([#4206](https://github.com/getsentry/relay/pull/4206))
2828
- Run internal worker threads with a lower priority. ([#4222](https://github.com/getsentry/relay/pull/4222))
29+
- Add additional fields to the `Event` `Getter`. ([#4238](https://github.com/getsentry/relay/pull/4238))
2930

3031
## 24.10.0
3132

relay-event-schema/src/protocol/event.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use uuid::Uuid;
1111
use crate::processor::ProcessValue;
1212
use crate::protocol::{
1313
AppContext, Breadcrumb, Breakdowns, BrowserContext, ClientSdkInfo, Contexts, Csp, DebugMeta,
14-
DefaultContext, DeviceContext, EventType, Exception, ExpectCt, ExpectStaple, Fingerprint, Hpkp,
15-
LenientString, Level, LogEntry, Measurements, Metrics, MetricsSummary, OsContext,
16-
ProfileContext, RelayInfo, Request, ResponseContext, Span, SpanId, Stacktrace, Tags,
17-
TemplateInfo, Thread, Timestamp, TraceContext, TransactionInfo, User, Values,
14+
DefaultContext, DeviceContext, EventType, Exception, ExpectCt, ExpectStaple, Fingerprint,
15+
GpuContext, Hpkp, LenientString, Level, LogEntry, Measurements, Metrics, MetricsSummary,
16+
MonitorContext, OsContext, ProfileContext, RelayInfo, Request, ResponseContext, RuntimeContext,
17+
Span, SpanId, Stacktrace, Tags, TemplateInfo, Thread, Timestamp, TraceContext, TransactionInfo,
18+
User, Values,
1819
};
1920

2021
/// Wrapper around a UUID with slightly different formatting.
@@ -674,6 +675,11 @@ impl Getter for Event {
674675
"contexts.app.in_foreground" => {
675676
self.context::<AppContext>()?.in_foreground.value()?.into()
676677
}
678+
"contexts.app.device_app_hash" => self
679+
.context::<AppContext>()?
680+
.device_app_hash
681+
.as_str()?
682+
.into(),
677683
"contexts.device.arch" => self.context::<DeviceContext>()?.arch.as_str()?.into(),
678684
"contexts.device.battery_level" => self
679685
.context::<DeviceContext>()?
@@ -713,12 +719,23 @@ impl Getter for Event {
713719
"contexts.device.simulator" => {
714720
self.context::<DeviceContext>()?.simulator.value()?.into()
715721
}
722+
"contexts.gpu.vendor_name" => {
723+
self.context::<GpuContext>()?.vendor_name.as_str()?.into()
724+
}
725+
"contexts.gpu.name" => self.context::<GpuContext>()?.name.as_str()?.into(),
726+
"contexts.monitor.id" => self.context::<MonitorContext>()?.get("id")?.value()?.into(),
727+
"contexts.monitor.slug" => self
728+
.context::<MonitorContext>()?
729+
.get("slug")?
730+
.value()?
731+
.into(),
716732
"contexts.os.build" => self.context::<OsContext>()?.build.as_str()?.into(),
717733
"contexts.os.kernel_version" => {
718734
self.context::<OsContext>()?.kernel_version.as_str()?.into()
719735
}
720736
"contexts.os.name" => self.context::<OsContext>()?.name.as_str()?.into(),
721737
"contexts.os.version" => self.context::<OsContext>()?.version.as_str()?.into(),
738+
"contexts.os.rooted" => self.context::<OsContext>()?.rooted.value()?.into(),
722739
"contexts.browser.name" => self.context::<BrowserContext>()?.name.as_str()?.into(),
723740
"contexts.browser.version" => {
724741
self.context::<BrowserContext>()?.version.as_str()?.into()
@@ -746,6 +763,7 @@ impl Getter for Event {
746763
super::Context::Other(context) => context.get("crash_type")?.value()?.into(),
747764
_ => return None,
748765
},
766+
"contexts.runtime.name" => self.context::<RuntimeContext>()?.name.as_str()?.into(),
749767

750768
// Computed fields (see Discover)
751769
"duration" => {
@@ -807,6 +825,7 @@ mod tests {
807825
use chrono::{TimeZone, Utc};
808826
use relay_protocol::{ErrorKind, Map, Meta};
809827
use similar_asserts::assert_eq;
828+
use std::collections::BTreeMap;
810829
use uuid::uuid;
811830

812831
use super::*;
@@ -1158,6 +1177,16 @@ mod tests {
11581177
))),
11591178
..ProfileContext::default()
11601179
});
1180+
let mut monitor_context_fields = BTreeMap::new();
1181+
monitor_context_fields.insert(
1182+
"id".to_string(),
1183+
Annotated::new(Value::String("123".to_string())),
1184+
);
1185+
monitor_context_fields.insert(
1186+
"slug".to_string(),
1187+
Annotated::new(Value::String("my_monitor".to_string())),
1188+
);
1189+
contexts.add(MonitorContext(monitor_context_fields));
11611190
contexts
11621191
}),
11631192
..Default::default()
@@ -1272,6 +1301,14 @@ mod tests {
12721301
Some(Val::String("message")),
12731302
event.get_value("event.logentry.message")
12741303
);
1304+
assert_eq!(
1305+
Some(Val::String("123")),
1306+
event.get_value("event.contexts.monitor.id")
1307+
);
1308+
assert_eq!(
1309+
Some(Val::String("my_monitor")),
1310+
event.get_value("event.contexts.monitor.slug")
1311+
);
12751312
}
12761313

12771314
#[test]

0 commit comments

Comments
 (0)