Skip to content

Commit 28eab25

Browse files
committed
improve
1 parent c90f2d7 commit 28eab25

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

sentry-core/src/performance.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::{Arc, Mutex, MutexGuard};
55
use std::time::SystemTime;
66

77
use sentry_types::protocol::v7::SpanId;
8+
use sentry_types::Dsn;
89

910
use crate::{protocol, Hub};
1011

@@ -594,10 +595,7 @@ fn transaction_sample_rate(
594595
) -> f32 {
595596
match (traces_sampler, traces_sample_rate) {
596597
(Some(traces_sampler), _) => traces_sampler(ctx),
597-
(None, traces_sample_rate) => ctx
598-
.sampled
599-
.map(|sampled| if sampled { 1.0 } else { 0.0 })
600-
.unwrap_or(traces_sample_rate),
598+
(None, traces_sample_rate) => ctx.sampled.map(f32::from).unwrap_or(traces_sample_rate),
601599
}
602600
}
603601

@@ -683,8 +681,7 @@ impl Transaction {
683681
None => (
684682
(
685683
ctx.sampled.unwrap_or(false),
686-
ctx.sampled
687-
.map_or(0.0, |sampled| if sampled { 1.0 } else { 0.0 }),
684+
ctx.sampled.map_or(0.0, f32::from),
688685
),
689686
None,
690687
),
@@ -840,17 +837,19 @@ impl Transaction {
840837
transaction.sdk = Some(std::borrow::Cow::Owned(client.sdk_info.clone()));
841838
transaction.server_name.clone_from(&opts.server_name);
842839

843-
let dsc = protocol::DynamicSamplingContext::new()
844-
.with_trace_id(Some(inner.context.trace_id))
845-
.with_sample_rate(Some(self.metadata.sample_rate))
846-
.with_public_key(opts.dsn.as_ref().map(|dsn| dsn.public_key().to_owned()))
847-
.with_sampled(Some(inner.sampled));
840+
let mut dsc = protocol::DynamicSamplingContext::new()
841+
.with_trace_id(inner.context.trace_id)
842+
.with_sample_rate(self.metadata.sample_rate)
843+
.with_sampled(inner.sampled);
844+
if let Some(public_key) = client.dsn().map(Dsn::public_key) {
845+
dsc = dsc.with_public_key(public_key.to_owned());
846+
}
848847

849848
drop(inner);
850849

851-
let mut envelope = protocol::Envelope::new();
852-
let headers = protocol::EnvelopeHeaders::new().with_trace(Some(dsc));
853-
envelope.set_headers(headers);
850+
let mut envelope = protocol::Envelope::new().with_headers(
851+
protocol::EnvelopeHeaders::new().with_trace(dsc)
852+
);
854853
envelope.add_item(transaction);
855854

856855
client.send_envelope(envelope)

0 commit comments

Comments
 (0)