Skip to content
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

feat: Add support of tracing::Span::record operation for sentry-tracing #364

Merged
merged 4 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes by rustfmt
  • Loading branch information
zryambus committed Sep 29, 2021
commit 3e46d15aaeba351f447cd7c3120b043bba7ef4f1
4 changes: 2 additions & 2 deletions sentry-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,13 @@ where
fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
let span = match ctx.span(span) {
Some(s) => s,
_ => return
_ => return,
};

let mut extensions_holder = span.extensions_mut();
let trace = match extensions_holder.get_mut::<Trace>() {
Some(t) => t,
_ => return
_ => return,
};

let mut data = BTreeMapRecorder::default();
Expand Down
25 changes: 17 additions & 8 deletions sentry/tests/test_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,32 @@ fn test_span_record() {
.with(sentry_tracing::layer())
.set_default();

let options = sentry::ClientOptions{
let options = sentry::ClientOptions {
traces_sample_rate: 1.0,
..Default::default()
};

let envelopes = sentry::test::with_captured_envelopes_options(|| {
let _span = tracing::span!(tracing::Level::INFO, "span").entered();
function();
}, options);
let envelopes = sentry::test::with_captured_envelopes_options(
|| {
let _span = tracing::span!(tracing::Level::INFO, "span").entered();
function();
},
options,
);

assert_eq!(envelopes.len(), 1);

let envelope_item = envelopes[0].items().next().unwrap();
let ref transaction = match envelope_item {
sentry::protocol::EnvelopeItem::Transaction(t) => t,
_ => { assert!(false); return; }
_ => {
assert!(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is test code, you can as well panic!("expected only a transaction item");
As the panic diverges, you also don’t need the return/block afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll know

return;
}
};

assert_eq!(transaction.spans[0].data["span_field"].as_str().unwrap(), "some data");
}
assert_eq!(
transaction.spans[0].data["span_field"].as_str().unwrap(),
"some data"
);
}