File tree 3 files changed +46
-4
lines changed
3 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -257,12 +257,12 @@ impl TransactionOrSpan {
257
257
}
258
258
259
259
#[ derive( Debug ) ]
260
- struct TransactionInner {
260
+ pub ( crate ) struct TransactionInner {
261
261
#[ cfg( feature = "client" ) ]
262
262
client : Option < Arc < Client > > ,
263
263
sampled : bool ,
264
264
context : protocol:: TraceContext ,
265
- transaction : Option < protocol:: Transaction < ' static > > ,
265
+ pub ( crate ) transaction : Option < protocol:: Transaction < ' static > > ,
266
266
}
267
267
268
268
type TransactionArc = Arc < Mutex < TransactionInner > > ;
@@ -274,7 +274,7 @@ type TransactionArc = Arc<Mutex<TransactionInner>>;
274
274
/// to Sentry.
275
275
#[ derive( Clone , Debug ) ]
276
276
pub struct Transaction {
277
- inner : TransactionArc ,
277
+ pub ( crate ) inner : TransactionArc ,
278
278
}
279
279
280
280
impl Transaction {
@@ -428,7 +428,7 @@ impl Transaction {
428
428
/// will not be sent to Sentry.
429
429
#[ derive( Clone , Debug ) ]
430
430
pub struct Span {
431
- transaction : TransactionArc ,
431
+ pub ( crate ) transaction : TransactionArc ,
432
432
sampled : bool ,
433
433
span : SpanArc ,
434
434
}
Original file line number Diff line number Diff line change @@ -160,6 +160,17 @@ impl Scope {
160
160
/// Sets the transaction.
161
161
pub fn set_transaction ( & mut self , transaction : Option < & str > ) {
162
162
self . transaction = transaction. map ( Arc :: from) ;
163
+ if let Some ( name) = transaction {
164
+ let trx = match self . span . as_ref ( ) {
165
+ Some ( TransactionOrSpan :: Span ( span) ) => & span. transaction ,
166
+ Some ( TransactionOrSpan :: Transaction ( trx) ) => & trx. inner ,
167
+ _ => return ,
168
+ } ;
169
+
170
+ if let Some ( trx) = trx. lock ( ) . unwrap ( ) . transaction . as_mut ( ) {
171
+ trx. name = Some ( name. into ( ) ) ;
172
+ }
173
+ }
163
174
}
164
175
165
176
/// Sets the user for the current scope.
Original file line number Diff line number Diff line change @@ -134,3 +134,34 @@ fn test_span_record() {
134
134
"some data"
135
135
) ;
136
136
}
137
+
138
+ #[ test]
139
+ fn test_set_transaction ( ) {
140
+ let options = sentry:: ClientOptions {
141
+ traces_sample_rate : 1.0 ,
142
+ ..Default :: default ( )
143
+ } ;
144
+
145
+ let envelopes = sentry:: test:: with_captured_envelopes_options (
146
+ || {
147
+ let ctx = sentry:: TransactionContext :: new ( "old name" , "ye, whatever" ) ;
148
+ let trx = sentry:: start_transaction ( ctx) ;
149
+ sentry:: configure_scope ( |scope| scope. set_span ( Some ( trx. clone ( ) . into ( ) ) ) ) ;
150
+
151
+ sentry:: configure_scope ( |scope| scope. set_transaction ( Some ( "new name" ) ) ) ;
152
+
153
+ trx. finish ( ) ;
154
+ } ,
155
+ options,
156
+ ) ;
157
+
158
+ assert_eq ! ( envelopes. len( ) , 1 ) ;
159
+
160
+ let envelope_item = envelopes[ 0 ] . items ( ) . next ( ) . unwrap ( ) ;
161
+ let transaction = match envelope_item {
162
+ sentry:: protocol:: EnvelopeItem :: Transaction ( t) => t,
163
+ _ => panic ! ( "expected only a transaction item" ) ,
164
+ } ;
165
+
166
+ assert_eq ! ( transaction. name. as_deref( ) . unwrap( ) , "new name" ) ;
167
+ }
You can’t perform that action at this time.
0 commit comments