@@ -5,6 +5,8 @@ use relay_dynamic_config::{RetentionConfig, RetentionsConfig};
55use relay_system:: { Addr , FromMessage } ;
66
77use crate :: Envelope ;
8+ #[ cfg( feature = "processing" ) ]
9+ use crate :: managed:: ManagedEnvelope ;
810use crate :: managed:: { Managed , Rejected } ;
911#[ cfg( feature = "processing" ) ]
1012use crate :: services:: objectstore:: Objectstore ;
@@ -18,12 +20,21 @@ use crate::services::store::Store;
1820pub struct StoreHandle < ' a > {
1921 store : & ' a Addr < Store > ,
2022 objectstore : Option < & ' a Addr < Objectstore > > ,
23+ global_config : & ' a GlobalConfig ,
2124}
2225
2326#[ cfg( feature = "processing" ) ]
2427impl < ' a > StoreHandle < ' a > {
25- pub fn new ( store : & ' a Addr < Store > , objectstore : Option < & ' a Addr < Objectstore > > ) -> Self {
26- Self { store, objectstore }
28+ pub fn new (
29+ store : & ' a Addr < Store > ,
30+ objectstore : Option < & ' a Addr < Objectstore > > ,
31+ global_config : & ' a GlobalConfig ,
32+ ) -> Self {
33+ Self {
34+ store,
35+ objectstore,
36+ global_config,
37+ }
2738 }
2839
2940 /// Sends a message to the [`Store`] service.
@@ -45,6 +56,36 @@ impl<'a> StoreHandle<'a> {
4556 relay_log:: error!( "Objectstore service not configured. Dropping message." ) ;
4657 }
4758 }
59+
60+ /// Dispatches an envelopes to either the [`Objectstore`] or [`Store`] service.
61+ pub fn send_envelope ( & self , envelope : ManagedEnvelope ) {
62+ use crate :: services:: store:: StoreEnvelope ;
63+
64+ let Some ( objectstore) = self . objectstore else {
65+ self . store . send ( StoreEnvelope { envelope } ) ;
66+ return ;
67+ } ;
68+
69+ let has_attachments = envelope
70+ . envelope ( )
71+ . items ( )
72+ . any ( |item| item. ty ( ) == & crate :: envelope:: ItemType :: Attachment ) ;
73+
74+ let use_objectstore = || {
75+ crate :: utils:: sample (
76+ self . global_config
77+ . options
78+ . objectstore_attachments_sample_rate ,
79+ )
80+ . is_keep ( )
81+ } ;
82+
83+ if has_attachments && use_objectstore ( ) {
84+ objectstore. send ( StoreEnvelope { envelope } )
85+ } else {
86+ self . store . send ( StoreEnvelope { envelope } ) ;
87+ }
88+ }
4889}
4990
5091/// A processor output which can be forwarded to a different destination.
@@ -73,7 +114,7 @@ pub struct ForwardContext<'a> {
73114 /// The Relay configuration.
74115 pub config : & ' a Config ,
75116 /// A view of the currently active global configuration.
76- #[ cfg_attr ( not ( feature = "processing" ) , expect ( unused ) ) ]
117+ #[ expect ( unused , reason = "not yet used" ) ]
77118 pub global_config : & ' a GlobalConfig ,
78119 /// Project configuration associated with the unit of work.
79120 pub project_info : & ' a ProjectInfo ,
0 commit comments