File tree Expand file tree Collapse file tree 4 files changed +13
-14
lines changed Expand file tree Collapse file tree 4 files changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -561,8 +561,8 @@ impl<'a> TransactionData<'a> {
561
561
562
562
impl Transaction {
563
563
#[ cfg( feature = "client" ) ]
564
- fn new ( mut client : Option < Arc < Client > > , ctx : TransactionContext ) -> Self {
565
- let ( sampled, mut transaction) = match client. as_ref ( ) {
564
+ fn new ( client : Option < Arc < Client > > , ctx : TransactionContext ) -> Self {
565
+ let ( sampled, transaction) = match client. as_ref ( ) {
566
566
Some ( client) => (
567
567
client. is_transaction_sampled ( & ctx) ,
568
568
Some ( protocol:: Transaction {
@@ -581,13 +581,6 @@ impl Transaction {
581
581
..Default :: default ( )
582
582
} ;
583
583
584
- // throw away the transaction here, which means there is nothing to send
585
- // on `finish`.
586
- if !sampled {
587
- transaction = None ;
588
- client = None ;
589
- }
590
-
591
584
Self {
592
585
inner : Arc :: new ( Mutex :: new ( TransactionInner {
593
586
client,
@@ -699,6 +692,12 @@ impl Transaction {
699
692
pub fn finish ( self ) {
700
693
with_client_impl ! { {
701
694
let mut inner = self . inner. lock( ) . unwrap( ) ;
695
+
696
+ // Discard `Transaction` unless sampled.
697
+ if !inner. sampled {
698
+ return ;
699
+ }
700
+
702
701
if let Some ( mut transaction) = inner. transaction. take( ) {
703
702
if let Some ( client) = inner. client. take( ) {
704
703
transaction. finish( ) ;
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ mod shared;
2
2
3
3
#[ test]
4
4
fn breadcrumbs_should_capture_span_fields ( ) {
5
- let transport = shared:: init_sentry ( ) ;
5
+ let transport = shared:: init_sentry ( 0.0 ) ; // This test should work even if we are not sampling transactions.
6
6
7
7
foo ( ) ;
8
8
9
9
let data = transport. fetch_and_clear_envelopes ( ) ;
10
- assert_eq ! ( data. len( ) , 2 ) ;
10
+ assert_eq ! ( data. len( ) , 1 ) ;
11
11
12
12
let event = data. first ( ) . expect ( "should have 1 event" ) ;
13
13
let event = match event. items ( ) . next ( ) . unwrap ( ) {
Original file line number Diff line number Diff line change @@ -3,15 +3,15 @@ use sentry_core::test::TestTransport;
3
3
4
4
use std:: sync:: Arc ;
5
5
6
- pub fn init_sentry ( ) -> Arc < TestTransport > {
6
+ pub fn init_sentry ( traces_sample_rate : f32 ) -> Arc < TestTransport > {
7
7
use tracing_subscriber:: prelude:: * ;
8
8
9
9
let transport = TestTransport :: new ( ) ;
10
10
let options = ClientOptions {
11
11
dsn : Some ( "https://test@sentry-tracing.com/test" . parse ( ) . unwrap ( ) ) ,
12
12
transport : Some ( Arc :: new ( transport. clone ( ) ) ) ,
13
13
sample_rate : 1.0 ,
14
- traces_sample_rate : 1.0 ,
14
+ traces_sample_rate,
15
15
..ClientOptions :: default ( )
16
16
} ;
17
17
Hub :: current ( ) . bind_client ( Some ( Arc :: new ( options. into ( ) ) ) ) ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ fn function_with_tags(value: i32) {
7
7
8
8
#[ test]
9
9
fn should_instrument_function_with_event ( ) {
10
- let transport = shared:: init_sentry ( ) ;
10
+ let transport = shared:: init_sentry ( 1.0 ) ; // Sample all spans.
11
11
12
12
function_with_tags ( 1 ) ;
13
13
You can’t perform that action at this time.
0 commit comments