@@ -5,6 +5,7 @@ use std::sync::{Arc, Mutex, MutexGuard};
5
5
use std:: time:: SystemTime ;
6
6
7
7
use sentry_types:: protocol:: v7:: SpanId ;
8
+ use sentry_types:: Dsn ;
8
9
9
10
use crate :: { protocol, Hub } ;
10
11
@@ -594,10 +595,7 @@ fn transaction_sample_rate(
594
595
) -> f32 {
595
596
match ( traces_sampler, traces_sample_rate) {
596
597
( 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) ,
601
599
}
602
600
}
603
601
@@ -683,8 +681,7 @@ impl Transaction {
683
681
None => (
684
682
(
685
683
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) ,
688
685
) ,
689
686
None ,
690
687
) ,
@@ -840,17 +837,19 @@ impl Transaction {
840
837
transaction. sdk = Some ( std:: borrow:: Cow :: Owned ( client. sdk_info. clone( ) ) ) ;
841
838
transaction. server_name. clone_from( & opts. server_name) ;
842
839
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
+ }
848
847
849
848
drop( inner) ;
850
849
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
+ ) ;
854
853
envelope. add_item( transaction) ;
855
854
856
855
client. send_envelope( envelope)
0 commit comments