@@ -526,32 +526,32 @@ pub struct Transaction {
526
526
pub ( crate ) inner : TransactionArc ,
527
527
}
528
528
529
- /// Iterable for a transaction's [`extra` field ](protocol::Transaction::extra ).
529
+ /// Iterable for a transaction's [data attributes ](protocol::TraceContext::data ).
530
530
pub struct TransactionData < ' a > ( MutexGuard < ' a , TransactionInner > ) ;
531
531
532
532
impl < ' a > TransactionData < ' a > {
533
- /// Iterate over the `extra` map
534
- /// of the [transaction][protocol::Transaction].
533
+ /// Iterate over the [data attributes](protocol::TraceContext::data)
534
+ /// associated with this [transaction][protocol::Transaction].
535
535
///
536
- /// If the transaction not sampled for sending,
537
- /// the metadata will not be populated at all
536
+ /// If the transaction is not sampled for sending,
537
+ /// the metadata will not be populated at all,
538
538
/// so the produced iterator is empty.
539
539
pub fn iter ( & self ) -> Box < dyn Iterator < Item = ( & String , & protocol:: Value ) > + ' _ > {
540
- if let Some ( ref rx ) = self . 0 . transaction {
541
- Box :: new ( rx . extra . iter ( ) )
540
+ if self . 0 . transaction . is_some ( ) {
541
+ Box :: new ( self . 0 . context . data . iter ( ) )
542
542
} else {
543
543
Box :: new ( std:: iter:: empty ( ) )
544
544
}
545
545
}
546
546
547
- /// Set some extra information to be sent with this Transaction.
547
+ /// Set a data attribute to be sent with this Transaction.
548
548
pub fn set_data ( & mut self , key : Cow < ' a , str > , value : protocol:: Value ) {
549
- if let Some ( transaction ) = self . 0 . transaction . as_mut ( ) {
550
- transaction . extra . insert ( key. into ( ) , value) ;
549
+ if self . 0 . transaction . is_some ( ) {
550
+ self . 0 . context . data . insert ( key. into ( ) , value) ;
551
551
}
552
552
}
553
553
554
- /// Set some extra information to be sent with this Transaction.
554
+ /// Set a tag to be sent with this Transaction.
555
555
pub fn set_tag ( & mut self , key : Cow < ' _ , str > , value : String ) {
556
556
if let Some ( transaction) = self . 0 . transaction . as_mut ( ) {
557
557
transaction. tags . insert ( key. into ( ) , value) ;
@@ -610,8 +610,16 @@ impl Transaction {
610
610
}
611
611
}
612
612
613
- /// Set some extra information to be sent with this Transaction.
613
+ /// Set a data attribute to be sent with this Transaction.
614
614
pub fn set_data ( & self , key : & str , value : protocol:: Value ) {
615
+ let mut inner = self . inner . lock ( ) . unwrap ( ) ;
616
+ if inner. transaction . is_some ( ) {
617
+ inner. context . data . insert ( key. into ( ) , value) ;
618
+ }
619
+ }
620
+
621
+ /// Set some extra information to be sent with this Transaction.
622
+ pub fn set_extra ( & self , key : & str , value : protocol:: Value ) {
615
623
let mut inner = self . inner . lock ( ) . unwrap ( ) ;
616
624
if let Some ( transaction) = inner. transaction . as_mut ( ) {
617
625
transaction. extra . insert ( key. into ( ) , value) ;
@@ -627,10 +635,10 @@ impl Transaction {
627
635
}
628
636
629
637
/// Returns an iterating accessor to the transaction's
630
- /// [`extra` field ](protocol::Transaction::extra ).
638
+ /// [data attributes ](protocol::TraceContext::data ).
631
639
///
632
640
/// # Concurrency
633
- /// In order to obtain any kind of reference to the `extra ` field,
641
+ /// In order to obtain any kind of reference to the `TraceContext::data ` field,
634
642
/// a `Mutex` needs to be locked. The returned `TransactionData` holds on to this lock
635
643
/// for as long as it lives. Therefore you must take care not to keep the returned
636
644
/// `TransactionData` around too long or it will never relinquish the lock and you may run into
0 commit comments