Skip to content

Commit 5bac740

Browse files
authored
feat(protocol): Improve the grouping protocol config (#190)
1 parent e23d3ec commit 5bac740

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

general/src/protocol/event.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ pub struct GroupingConfig {
172172
/// The id of the grouping config.
173173
#[metastructure(max_chars = "enumlike")]
174174
pub id: Annotated<String>,
175+
/// The enhancements configuration.
176+
pub enhancements: Annotated<String>,
175177
}
176178

177179
/// The sentry v7 event structure.
@@ -337,7 +339,7 @@ pub struct Event {
337339
pub project: Annotated<u64>,
338340

339341
/// The grouping configuration for this event.
340-
pub grouping_config: Annotated<GroupingConfig>,
342+
pub grouping_config: Annotated<Object<Value>>,
341343

342344
/// Legacy checksum used for grouping before fingerprint hashes.
343345
#[metastructure(max_chars = "hash")]

general/src/store/mod.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use std::collections::BTreeSet;
33
use std::sync::Arc;
44

55
use serde::{Deserialize, Serialize};
6+
use serde_json::Value;
67

78
use crate::processor::{ProcessingState, Processor};
8-
use crate::protocol::{Event, GroupingConfig, IpAddr};
9-
use crate::types::{Annotated, Meta, ValueAction};
9+
use crate::protocol::{Event, IpAddr};
10+
use crate::types::{Meta, ValueAction};
1011

1112
mod event_error;
1213
mod geo;
@@ -18,23 +19,6 @@ mod trimming;
1819

1920
pub use crate::store::geo::GeoIpLookup;
2021

21-
/// The config for the grouping config in store
22-
#[derive(Serialize, Deserialize, Debug, Default)]
23-
#[serde(default)]
24-
pub struct StoreGroupingConfig {
25-
/// The id of the grouping algorithm that should be used.
26-
pub id: String,
27-
}
28-
29-
impl StoreGroupingConfig {
30-
/// Converts this config into one the event structure supports.
31-
pub fn as_grouping_config(&self) -> GroupingConfig {
32-
GroupingConfig {
33-
id: Annotated::from(self.id.clone()),
34-
}
35-
}
36-
}
37-
3822
/// The config for store.
3923
#[derive(Serialize, Deserialize, Debug, Default)]
4024
#[serde(default)]
@@ -44,7 +28,7 @@ pub struct StoreConfig {
4428
pub client: Option<String>,
4529
pub key_id: Option<String>,
4630
pub protocol_version: Option<String>,
47-
pub grouping_config: Option<StoreGroupingConfig>,
31+
pub grouping_config: Option<Value>,
4832

4933
/// Hard limit for stacktrace frames
5034
/// Corresponds to SENTRY_STACKTRACE_FRAMES_HARD_LIMIT

general/src/store/normalize.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use crate::protocol::{
1616
Frame, IpAddr, Level, LogEntry, Request, Stacktrace, Tags, User,
1717
};
1818
use crate::store::{GeoIpLookup, StoreConfig};
19-
use crate::types::{Annotated, Empty, Error, ErrorKind, Meta, Object, ValueAction};
19+
use crate::types::{
20+
Annotated, Empty, Error, ErrorKind, FromValue, Meta, Object, Value, ValueAction,
21+
};
2022

2123
mod contexts;
2224
mod logentry;
@@ -293,12 +295,13 @@ impl<'a> Processor for NormalizeProcessor<'a> {
293295
event.key_id = Annotated::from(self.config.key_id.clone());
294296
event.ty = Annotated::from(self.infer_event_type(event));
295297
event.version = Annotated::from(self.config.protocol_version.clone());
296-
event.grouping_config = Annotated::from(
297-
self.config
298-
.grouping_config
299-
.as_ref()
300-
.map(|x| x.as_grouping_config()),
301-
);
298+
event.grouping_config = self
299+
.config
300+
.grouping_config
301+
.clone()
302+
.map_or(Annotated::empty(), |x| {
303+
FromValue::from_value(Annotated::<Value>::from(x))
304+
});
302305

303306
// Validate basic attributes
304307
event.platform.apply(|platform, _| {
@@ -542,7 +545,6 @@ impl<'a> Processor for NormalizeProcessor<'a> {
542545
use crate::{
543546
processor::process_value,
544547
protocol::{PairList, TagEntry},
545-
types::Value,
546548
};
547549

548550
#[cfg(test)]
@@ -1179,9 +1181,9 @@ fn test_discards_received() {
11791181
#[test]
11801182
fn test_grouping_config() {
11811183
use crate::protocol::LogEntry;
1182-
use crate::store::StoreGroupingConfig;
11831184
use crate::types::SerializableAnnotated;
11841185
use insta::assert_ron_snapshot_matches;
1186+
use serde_json::json;
11851187

11861188
let mut event = Annotated::new(Event {
11871189
logentry: Annotated::from(LogEntry {
@@ -1193,9 +1195,9 @@ fn test_grouping_config() {
11931195

11941196
let mut processor = NormalizeProcessor::new(
11951197
Arc::new(StoreConfig {
1196-
grouping_config: Some(StoreGroupingConfig {
1197-
id: "legacy:1234-12-12".into(),
1198-
}),
1198+
grouping_config: Some(json!({
1199+
"id": "legacy:1234-12-12".to_string(),
1200+
})),
11991201
..Default::default()
12001202
}),
12011203
None,

0 commit comments

Comments
 (0)