@@ -11,7 +11,7 @@ use rand::random;
1111use crate :: constants:: SDK_INFO ;
1212use crate :: protocol:: { ClientSdkInfo , Event } ;
1313use crate :: types:: { Dsn , Uuid } ;
14- use crate :: { ClientOptions , Hub , Integration , Scope , Transport } ;
14+ use crate :: { ClientOptions , Envelope , Hub , Integration , Scope , Transport } ;
1515
1616impl < T : Into < ClientOptions > > From < T > for Client {
1717 fn from ( o : T ) -> Client {
@@ -142,6 +142,14 @@ impl Client {
142142 mut event : Event < ' static > ,
143143 scope : Option < & Scope > ,
144144 ) -> Option < Event < ' static > > {
145+ if let Some ( scope) = scope {
146+ scope. update_session_from_event ( & event) ;
147+ }
148+
149+ if !self . sample_should_send ( ) {
150+ return None ;
151+ }
152+
145153 // event_id and sdk_info are set before the processors run so that the
146154 // processors can poke around in that data.
147155 if event. event_id . is_nil ( ) {
@@ -236,17 +244,33 @@ impl Client {
236244 /// Captures an event and sends it to sentry.
237245 pub fn capture_event ( & self , event : Event < ' static > , scope : Option < & Scope > ) -> Uuid {
238246 if let Some ( ref transport) = * self . transport . read ( ) . unwrap ( ) {
239- if self . sample_should_send ( ) {
240- if let Some ( event) = self . prepare_event ( event, scope) {
241- let event_id = event. event_id ;
242- transport. send_envelope ( event. into ( ) ) ;
243- return event_id;
247+ if let Some ( event) = self . prepare_event ( event, scope) {
248+ let event_id = event. event_id ;
249+ let mut envelope: Envelope = event. into ( ) ;
250+ let session_item = scope. and_then ( |scope| {
251+ scope
252+ . session
253+ . lock ( )
254+ . unwrap ( )
255+ . as_mut ( )
256+ . and_then ( |session| session. create_envelope_item ( ) )
257+ } ) ;
258+ if let Some ( session_item) = session_item {
259+ envelope. add ( session_item) ;
244260 }
261+ transport. send_envelope ( envelope) ;
262+ return event_id;
245263 }
246264 }
247265 Default :: default ( )
248266 }
249267
268+ pub ( crate ) fn capture_envelope ( & self , envelope : Envelope ) {
269+ if let Some ( ref transport) = * self . transport . read ( ) . unwrap ( ) {
270+ transport. send_envelope ( envelope) ;
271+ }
272+ }
273+
250274 /// Drains all pending events and shuts down the transport behind the
251275 /// client. After shutting down the transport is removed.
252276 ///
0 commit comments