From 57159bfbd93b4802e7f4c2b6adce71b2f4823338 Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Mon, 7 Jul 2025 17:11:44 -0400 Subject: [PATCH] feat: Inline context for custom and migration op events --- contract-tests/src/main.rs | 2 +- .../src/events/dispatcher.rs | 15 +++++++-- launchdarkly-server-sdk/src/events/event.rs | 32 ++++++++++++++++++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/contract-tests/src/main.rs b/contract-tests/src/main.rs index 575caa8..4bd4ff2 100644 --- a/contract-tests/src/main.rs +++ b/contract-tests/src/main.rs @@ -105,7 +105,7 @@ async fn status() -> impl Responder { "service-endpoints".to_string(), "context-type".to_string(), "secure-mode-hash".to_string(), - "inline-context".to_string(), + "inline-context-all".to_string(), "anonymous-redaction".to_string(), "omit-anonymous-contexts".to_string(), "migrations".to_string(), diff --git a/launchdarkly-server-sdk/src/events/dispatcher.rs b/launchdarkly-server-sdk/src/events/dispatcher.rs index e208342..df59165 100644 --- a/launchdarkly-server-sdk/src/events/dispatcher.rs +++ b/launchdarkly-server-sdk/src/events/dispatcher.rs @@ -192,8 +192,12 @@ impl EventDispatcher { .sampler .sample(migration_op.sampling_ratio.unwrap_or(1)) { - self.outbox - .add_event(OutputEvent::MigrationOp(migration_op)); + self.outbox.add_event(OutputEvent::MigrationOp( + migration_op.into_inline_with_anonymous_redaction( + self.events_configuration.all_attributes_private, + self.events_configuration.private_attributes.clone(), + ), + )); } } InputEvent::FeatureRequest(fre) => { @@ -266,7 +270,12 @@ impl EventDispatcher { } if self.sampler.sample(custom.sampling_ratio.unwrap_or(1)) { - self.outbox.add_event(OutputEvent::Custom(custom)); + self.outbox.add_event(OutputEvent::Custom( + custom.into_inline_with_anonymous_redaction( + self.events_configuration.all_attributes_private, + self.events_configuration.private_attributes.clone(), + ), + )); } } } diff --git a/launchdarkly-server-sdk/src/events/event.rs b/launchdarkly-server-sdk/src/events/event.rs index abace01..741694b 100644 --- a/launchdarkly-server-sdk/src/events/event.rs +++ b/launchdarkly-server-sdk/src/events/event.rs @@ -112,6 +112,22 @@ pub struct MigrationOpEvent { pub(crate) latency: HashMap, } +impl MigrationOpEvent { + pub(crate) fn into_inline_with_anonymous_redaction( + self, + all_attribute_private: bool, + global_private_attributes: HashSet, + ) -> Self { + Self { + base: self.base.into_inline_with_anonymous_redaction( + all_attribute_private, + global_private_attributes, + ), + ..self + } + } +} + impl Serialize for MigrationOpEvent { fn serialize(&self, serializer: S) -> Result where @@ -120,7 +136,7 @@ impl Serialize for MigrationOpEvent { let mut state = serializer.serialize_struct("MigrationOpEvent", 10)?; state.serialize_field("kind", "migration_op")?; state.serialize_field("creationDate", &self.base.creation_date)?; - state.serialize_field("contextKeys", &self.base.context.context_keys())?; + state.serialize_field("context", &self.base.context)?; state.serialize_field("operation", &self.operation)?; if !is_default_ratio(&self.sampling_ratio) { @@ -369,6 +385,20 @@ pub struct CustomEvent { } impl CustomEvent { + pub(crate) fn into_inline_with_anonymous_redaction( + self, + all_attribute_private: bool, + global_private_attributes: HashSet, + ) -> Self { + Self { + base: self.base.into_inline_with_anonymous_redaction( + all_attribute_private, + global_private_attributes, + ), + ..self + } + } + pub fn to_index_event( &self, all_attribute_private: bool,