Skip to content

Commit 2c93921

Browse files
authored
Fix rate-limiting/filtering of raw envelopes (#579)
It turns out, raw envelopes were never ever send out via transports that support rate-limiting, as the `filter` would discard raw envelopes.
1 parent b5d7953 commit 2c93921

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

sentry-types/src/protocol/envelope.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ pub enum EnvelopeItem {
109109
Attachment(Attachment),
110110
/// A Profile Item.
111111
Profile(SampleProfile),
112+
/// This is a sentinel item used to `filter` raw envelopes.
113+
Raw,
112114
// TODO:
113115
// etc…
114116
}
@@ -213,12 +215,15 @@ impl Envelope {
213215
where
214216
I: Into<EnvelopeItem>,
215217
{
218+
let item = item.into();
219+
216220
let Items::EnvelopeItems(ref mut items) = self.items else {
217-
eprintln!("WARNING: This envelope contains raw items. Adding an item is not supported.");
221+
if item != EnvelopeItem::Raw {
222+
eprintln!("WARNING: This envelope contains raw items. Adding an item is not supported.");
223+
}
218224
return;
219225
};
220226

221-
let item = item.into();
222227
if self.event_id.is_none() {
223228
if let EnvelopeItem::Event(ref event) = item {
224229
self.event_id = Some(event.event_id);
@@ -271,7 +276,7 @@ impl Envelope {
271276
P: FnMut(&EnvelopeItem) -> bool,
272277
{
273278
let Items::EnvelopeItems(items) = self.items else {
274-
return None;
279+
return if predicate(&EnvelopeItem::Raw) { Some(self) } else { None };
275280
};
276281

277282
let mut filtered = Envelope::new();
@@ -336,13 +341,16 @@ impl Envelope {
336341
continue;
337342
}
338343
EnvelopeItem::Profile(profile) => serde_json::to_writer(&mut item_buf, profile)?,
344+
EnvelopeItem::Raw => {
345+
continue;
346+
}
339347
}
340348
let item_type = match item {
341349
EnvelopeItem::Event(_) => "event",
342350
EnvelopeItem::SessionUpdate(_) => "session",
343351
EnvelopeItem::SessionAggregates(_) => "sessions",
344352
EnvelopeItem::Transaction(_) => "transaction",
345-
EnvelopeItem::Attachment(_) => unreachable!(),
353+
EnvelopeItem::Attachment(_) | EnvelopeItem::Raw => unreachable!(),
346354
EnvelopeItem::Profile(_) => "profile",
347355
};
348356
writeln!(

sentry/examples/tracing-demo.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,28 @@ fn main_span1() {
3434
thread::spawn(move || {
3535
thread::sleep(Duration::from_millis(50));
3636

37-
thread_span1();
37+
thread_span1("foo");
3838

3939
tracing::error!("Holy shit everything is on fire!");
4040
});
4141
thread::sleep(Duration::from_millis(100));
4242

43-
main_span2()
43+
main_span2(SomeArgument::default())
4444
}
4545

4646
#[tracing::instrument]
47-
fn thread_span1() {
47+
fn thread_span1(_arg: &str) {
4848
thread::sleep(Duration::from_millis(200));
4949
}
5050

5151
#[tracing::instrument]
52-
fn main_span2() {
52+
fn main_span2(_arg: SomeArgument) {
5353
thread::sleep(Duration::from_millis(200));
5454
}
55+
56+
#[derive(Debug, Default)]
57+
struct SomeArgument {
58+
_a: u32,
59+
_b: bool,
60+
_c: &'static str,
61+
}

0 commit comments

Comments
 (0)