diff --git a/eppo_core/src/event_ingestion/event_ingestion.rs b/eppo_core/src/event_ingestion/event_ingestion.rs index 29e18dc2..74c077ca 100644 --- a/eppo_core/src/event_ingestion/event_ingestion.rs +++ b/eppo_core/src/event_ingestion/event_ingestion.rs @@ -128,8 +128,10 @@ impl EventIngestion { /// @param key - The context entry key. /// @param value - The context entry value, must be a string, number, boolean, or null. If value is /// an object or an array, will throw an ArgumentError. - pub fn attach_context(&mut self, key: String, value: Value) -> Result<(), ContextError> { - self.event_delivery.attach_context(key, value) + pub fn attach_context(&mut self, key: String, value: Value) { + if let Err(err) = self.event_delivery.attach_context(key, value) { + log::warn!(target: "eppo", "failed to attach context: {}", err); + } } fn track_event(&self, event: Event) { diff --git a/ruby-sdk/ext/eppo_client/src/client.rs b/ruby-sdk/ext/eppo_client/src/client.rs index ddafdced..71c6bb28 100644 --- a/ruby-sdk/ext/eppo_client/src/client.rs +++ b/ruby-sdk/ext/eppo_client/src/client.rs @@ -55,15 +55,6 @@ impl TryConvert for Config { } } -#[magnus::wrap(class = "EventIngestion")] -struct MutEventIngestion(RefCell); - -impl MutEventIngestion { - pub fn new(event_ingestion: EventIngestion) -> Self { - Self(RefCell::new(event_ingestion)) - } -} - #[magnus::wrap(class = "EppoClient::Core::Client")] pub struct Client { configuration_store: Arc, @@ -76,7 +67,7 @@ pub struct Client { // world. background_thread: RefCell>, configuration_poller: Option, - event_ingestion: Option, + event_ingestion: RefCell>, } impl Client { @@ -129,14 +120,14 @@ impl Client { let event_ingestion = config .event_ingestion_config - .map(|config| MutEventIngestion::new(config.spawn(background_thread.runtime()))); + .map(|config| config.spawn(background_thread.runtime())); Client { configuration_store, evaluator, background_thread: RefCell::new(Some(background_thread)), configuration_poller, - event_ingestion, + event_ingestion: RefCell::new(event_ingestion), } } @@ -265,7 +256,8 @@ impl Client { } pub fn set_context(&self, key: String, value: Value) -> Result<()> { - let Some(event_ingestion) = &self.event_ingestion else { + let mut binding = self.event_ingestion.borrow_mut(); + let Some(event_ingestion) = binding.as_mut() else { // Event ingestion is disabled, do nothing. return Ok(()); }; @@ -276,13 +268,13 @@ impl Client { ) })?; - event_ingestion.0.borrow_mut().attach_context(key, value); + event_ingestion.attach_context(key, value); Ok(()) } - pub fn track(&self, event_type: String, payload: Value) -> Result<()> { - let Some(event_ingestion) = &self.event_ingestion else { + let binding = self.event_ingestion.borrow(); + let Some(event_ingestion) = binding.as_ref() else { // Event ingestion is disabled, do nothing. return Ok(()); }; @@ -294,7 +286,7 @@ impl Client { ) })?; - event_ingestion.0.borrow().track(event_type, payload); + event_ingestion.track(event_type, payload); Ok(()) }