-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sentry-tracing): add span fields to breadcrumbs (#708)
- Loading branch information
1 parent
05fc7de
commit eb902e0
Showing
8 changed files
with
74 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Integration tests for `sentry-tracing` | ||
|
||
These tests are split up into 1 file per test to ensure they don't run concurrently. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
mod shared; | ||
|
||
#[test] | ||
fn breadcrumbs_should_capture_span_fields() { | ||
let transport = shared::init_sentry(); | ||
|
||
foo(); | ||
|
||
let data = transport.fetch_and_clear_envelopes(); | ||
assert_eq!(data.len(), 2); | ||
|
||
let event = data.first().expect("should have 1 event"); | ||
let event = match event.items().next().unwrap() { | ||
sentry::protocol::EnvelopeItem::Event(event) => event, | ||
unexpected => panic!("Expected event, but got {:#?}", unexpected), | ||
}; | ||
|
||
assert_eq!(event.breadcrumbs.len(), 1); | ||
assert_eq!( | ||
event.breadcrumbs[0].data["foo:contextual_value"], | ||
serde_json::Value::from(42) | ||
); | ||
assert_eq!( | ||
event.breadcrumbs[0].message, | ||
Some("executing foo".to_owned()) | ||
); | ||
} | ||
|
||
#[tracing::instrument(fields(contextual_value = 42))] | ||
fn foo() { | ||
tracing::info!("executing foo"); | ||
|
||
tracing::error!("boom!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use sentry::{ClientOptions, Hub}; | ||
use sentry_core::test::TestTransport; | ||
|
||
use std::sync::Arc; | ||
|
||
pub fn init_sentry() -> Arc<TestTransport> { | ||
use tracing_subscriber::prelude::*; | ||
|
||
let transport = TestTransport::new(); | ||
let options = ClientOptions { | ||
dsn: Some("https://[email protected]/test".parse().unwrap()), | ||
transport: Some(Arc::new(transport.clone())), | ||
sample_rate: 1.0, | ||
traces_sample_rate: 1.0, | ||
..ClientOptions::default() | ||
}; | ||
Hub::current().bind_client(Some(Arc::new(options.into()))); | ||
|
||
let _ = tracing_subscriber::registry() | ||
.with(sentry_tracing::layer().enable_span_attributes()) | ||
.try_init(); | ||
|
||
transport | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,4 @@ | ||
use sentry::{ClientOptions, Hub}; | ||
use sentry_core::test::TestTransport; | ||
|
||
use std::sync::Arc; | ||
|
||
fn init_sentry() -> Arc<TestTransport> { | ||
use tracing_subscriber::prelude::*; | ||
|
||
let transport = TestTransport::new(); | ||
let options = ClientOptions { | ||
dsn: Some("https://[email protected]/test".parse().unwrap()), | ||
transport: Some(Arc::new(transport.clone())), | ||
sample_rate: 1.0, | ||
traces_sample_rate: 1.0, | ||
..ClientOptions::default() | ||
}; | ||
Hub::current().bind_client(Some(Arc::new(options.into()))); | ||
|
||
let _ = tracing_subscriber::registry() | ||
.with(sentry_tracing::layer().enable_span_attributes()) | ||
.try_init(); | ||
|
||
transport | ||
} | ||
mod shared; | ||
|
||
#[tracing::instrument(fields(tags.tag = "key", not_tag = "value"))] | ||
fn function_with_tags(value: i32) { | ||
|
@@ -30,7 +7,7 @@ fn function_with_tags(value: i32) { | |
|
||
#[test] | ||
fn should_instrument_function_with_event() { | ||
let transport = init_sentry(); | ||
let transport = shared::init_sentry(); | ||
|
||
function_with_tags(1); | ||
|
||
|