Skip to content

Commit ebe32b5

Browse files
committed
fix: Changes from PR review and lint warnings
1 parent f120ad0 commit ebe32b5

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

Diff for: sentry-tracing/src/converters.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ where
122122
..TraceContext::default()
123123
});
124124

125-
result.contexts.insert(context.type_name().into(), context);
125+
result.contexts.insert(String::from("trace"), context);
126+
126127
result.transaction = parent
127128
.parent()
128129
.into_iter()

Diff for: sentry-tracing/src/layer.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ where
8080
let (description, data) = extract_span_data(attrs);
8181

8282
let trace_id = parent
83-
.map(|parent| parent.trace_id.clone())
83+
.map(|parent| parent.trace_id)
8484
.unwrap_or_else(TraceId::default);
8585

8686
protocol::Span {
@@ -127,9 +127,9 @@ where
127127
span_id: sentry_span.span_id,
128128
trace_id: sentry_span.trace_id,
129129
parent_span_id: sentry_span.parent_span_id,
130-
op: sentry_span.op.clone(),
131-
description: sentry_span.description.clone(),
132-
status: sentry_span.status.clone(),
130+
op: sentry_span.op,
131+
description: sentry_span.description,
132+
status: sentry_span.status,
133133
})),
134134
);
135135

@@ -291,7 +291,10 @@ where
291291
/// When a new Span gets created, run the filter and initialize the trace extension
292292
/// if it passes
293293
fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
294-
let span = ctx.span(id).expect("Span not found, this is a bug");
294+
let span = match ctx.span(id) {
295+
Some(span) => span,
296+
None => return,
297+
};
295298

296299
if !(self.span_filter)(span.metadata()) {
297300
return;
@@ -319,9 +322,12 @@ where
319322
/// From the tracing-subscriber implementation of span timings,
320323
/// keep track of when the span was last entered
321324
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
322-
let span = ctx.span(id).expect("Span not found, this is a bug");
323-
let mut extensions = span.extensions_mut();
325+
let span = match ctx.span(id) {
326+
Some(span) => span,
327+
None => return,
328+
};
324329

330+
let mut extensions = span.extensions_mut();
325331
if let Some(timings) = extensions.get_mut::<Trace>() {
326332
let now = Instant::now();
327333
timings.idle += (now - timings.last).as_nanos() as u64;
@@ -332,9 +338,12 @@ where
332338
/// From the tracing-subscriber implementation of span timings,
333339
/// keep track of when the span was last exited
334340
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
335-
let span = ctx.span(id).expect("Span not found, this is a bug");
336-
let mut extensions = span.extensions_mut();
341+
let span = match ctx.span(id) {
342+
Some(span) => span,
343+
None => return,
344+
};
337345

346+
let mut extensions = span.extensions_mut();
338347
if let Some(timings) = extensions.get_mut::<Trace>() {
339348
let now = Instant::now();
340349
timings.busy += (now - timings.last).as_nanos() as u64;
@@ -347,9 +356,12 @@ where
347356
/// attach it to a parent span or submit it as a Transaction if
348357
/// it is a root of the span tree
349358
fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
350-
let span = ctx.span(&id).expect("Span not found, this is a bug");
351-
let mut extensions = span.extensions_mut();
359+
let span = match ctx.span(&id) {
360+
Some(span) => span,
361+
None => return,
362+
};
352363

364+
let mut extensions = span.extensions_mut();
353365
let mut trace = match extensions.remove::<Trace>() {
354366
Some(trace) => trace,
355367
None => return,
@@ -384,7 +396,11 @@ where
384396
// transaction root and submit it to Sentry
385397
let span = &span;
386398
Hub::with_active(move |hub| {
387-
let client = hub.client().unwrap();
399+
let client = match hub.client() {
400+
Some(client) => client,
401+
None => return,
402+
};
403+
388404
if !client.sample_traces_should_send() {
389405
return;
390406
}

Diff for: sentry-tracing/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
//! use tracing_subscriber::prelude::*;
4141
//! use sentry_tracing::EventFilter;
4242
//!
43+
//! let layer = sentry_tracing::layer().event_filter(|md| match md.level() {
44+
//! &tracing::Level::ERROR => EventFilter::Event,
45+
//! _ => EventFilter::Ignore,
46+
//! });
47+
//!
4348
//! tracing_subscriber::registry()
44-
//! .with(
45-
//! sentry_tracing::layer().event_filter(|md| match md.level() {
46-
//! &tracing::Level::ERROR => EventFilter::Event,
47-
//! _ => EventFilter::Ignore,
48-
//! })
49-
//! )
49+
//! .with(layer)
5050
//! .try_init()
5151
//! .unwrap();
5252
//! ```

0 commit comments

Comments
 (0)