-
-
Notifications
You must be signed in to change notification settings - Fork 184
chore: Record transaction and span drops in client reports #1192
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ use std::sync::Arc; | |
| use sentry_core::protocol::client_report::Reason; | ||
| use sentry_core::protocol::{EnvelopeItem, Event}; | ||
| use sentry_core::test::TestTransport; | ||
| use sentry_core::{Client, ClientOptions, Envelope, Integration, Scope}; | ||
| use sentry_core::{Client, ClientOptions, Envelope, Hub, Integration, Scope, TransactionContext}; | ||
|
|
||
| struct DroppingIntegration; | ||
|
|
||
|
|
@@ -27,7 +27,7 @@ fn client_with_options(transport: Arc<TestTransport>, options: ClientOptions) -> | |
| }) | ||
| } | ||
|
|
||
| fn assert_client_report(envelope: &Envelope, reason: Reason) { | ||
| fn assert_client_report(envelope: &Envelope, expected: serde_json::Value) { | ||
| let client_report = envelope | ||
| .items() | ||
| .find_map(|item| match item { | ||
|
|
@@ -37,10 +37,7 @@ fn assert_client_report(envelope: &Envelope, reason: Reason) { | |
| .expect("envelope should contain a client report"); | ||
|
|
||
| let value = serde_json::to_value(client_report).unwrap(); | ||
| assert_eq!( | ||
| value["discarded_events"], | ||
| serde_json::json!([{ "category": "error", "reason": reason, "quantity": 1 }]) | ||
| ); | ||
| assert_eq!(value["discarded_events"], expected); | ||
| } | ||
|
|
||
| fn assert_drop_records_client_report<F>(options: ClientOptions, capture: F, reason: Reason) | ||
|
|
@@ -55,7 +52,10 @@ where | |
|
|
||
| let envelopes = transport.fetch_and_clear_envelopes(); | ||
| assert_eq!(envelopes.len(), 1); | ||
| assert_client_report(&envelopes[0], reason); | ||
| assert_client_report( | ||
| &envelopes[0], | ||
| serde_json::json!([{ "category": "error", "reason": reason, "quantity": 1 }]), | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
@@ -116,3 +116,70 @@ fn client_report_records_sample_rate_drop() { | |
| Reason::SampleRate, | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn client_report_records_unsampled_transaction_and_spans() { | ||
| let transport = TestTransport::new(); | ||
| let client = Arc::new(client_with_options( | ||
| transport.clone(), | ||
| ClientOptions { | ||
| traces_sample_rate: 0.0, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct behavior? Basically if tracing is fully disabled, we still report everything as dropped due to |
||
| ..Default::default() | ||
| }, | ||
| )); | ||
|
|
||
| Hub::run( | ||
| Arc::new(Hub::new(Some(client.clone()), Arc::new(Default::default()))), | ||
| || { | ||
| let transaction = sentry_core::start_transaction(TransactionContext::new("tx", "op")); | ||
| transaction.start_child("child", "one").finish(); | ||
| transaction.start_child("child", "two").finish(); | ||
| transaction.finish(); | ||
| }, | ||
| ); | ||
| client.send_envelope(Envelope::new()); | ||
|
|
||
| let envelopes = transport.fetch_and_clear_envelopes(); | ||
| assert_eq!(envelopes.len(), 1); | ||
| assert_client_report( | ||
| &envelopes[0], | ||
| serde_json::json!([ | ||
| { "category": "transaction", "reason": "sample_rate", "quantity": 1 }, | ||
| { "category": "span", "reason": "sample_rate", "quantity": 3 }, | ||
| ]), | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn client_report_records_transaction_span_cap_drop() { | ||
| // Keep in sync with `MAX_SPANS` in `sentry-core/src/performance.rs`. | ||
| const MAX_SPANS: usize = 1_000; | ||
|
|
||
| let transport = TestTransport::new(); | ||
| let client = Arc::new(client_with_options( | ||
| transport.clone(), | ||
| ClientOptions { | ||
| traces_sample_rate: 1.0, | ||
| ..Default::default() | ||
| }, | ||
| )); | ||
|
|
||
| Hub::run( | ||
| Arc::new(Hub::new(Some(client.clone()), Arc::new(Default::default()))), | ||
| || { | ||
| let transaction = sentry_core::start_transaction(TransactionContext::new("tx", "op")); | ||
| for _ in 0..=MAX_SPANS { | ||
| transaction.start_child("child", "kept").finish(); | ||
| } | ||
| transaction.start_child("child", "dropped").finish(); | ||
| }, | ||
| ); | ||
| client.send_envelope(Envelope::new()); | ||
|
|
||
| let envelopes = transport.fetch_and_clear_envelopes(); | ||
| assert_eq!(envelopes.len(), 1); | ||
| assert_client_report( | ||
| &envelopes[0], | ||
| serde_json::json!([{ "category": "span", "reason": "buffer_overflow", "quantity": 1 }]), | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.