Skip to content

Commit 7a5da5c

Browse files
authored
feat: Inline context for custom and migration op events (#120)
1 parent e55c176 commit 7a5da5c

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

contract-tests/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async fn status() -> impl Responder {
105105
"service-endpoints".to_string(),
106106
"context-type".to_string(),
107107
"secure-mode-hash".to_string(),
108-
"inline-context".to_string(),
108+
"inline-context-all".to_string(),
109109
"anonymous-redaction".to_string(),
110110
"omit-anonymous-contexts".to_string(),
111111
"migrations".to_string(),

launchdarkly-server-sdk/src/events/dispatcher.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,12 @@ impl EventDispatcher {
192192
.sampler
193193
.sample(migration_op.sampling_ratio.unwrap_or(1))
194194
{
195-
self.outbox
196-
.add_event(OutputEvent::MigrationOp(migration_op));
195+
self.outbox.add_event(OutputEvent::MigrationOp(
196+
migration_op.into_inline_with_anonymous_redaction(
197+
self.events_configuration.all_attributes_private,
198+
self.events_configuration.private_attributes.clone(),
199+
),
200+
));
197201
}
198202
}
199203
InputEvent::FeatureRequest(fre) => {
@@ -266,7 +270,12 @@ impl EventDispatcher {
266270
}
267271

268272
if self.sampler.sample(custom.sampling_ratio.unwrap_or(1)) {
269-
self.outbox.add_event(OutputEvent::Custom(custom));
273+
self.outbox.add_event(OutputEvent::Custom(
274+
custom.into_inline_with_anonymous_redaction(
275+
self.events_configuration.all_attributes_private,
276+
self.events_configuration.private_attributes.clone(),
277+
),
278+
));
270279
}
271280
}
272281
}

launchdarkly-server-sdk/src/events/event.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ pub struct MigrationOpEvent {
112112
pub(crate) latency: HashMap<Origin, Duration>,
113113
}
114114

115+
impl MigrationOpEvent {
116+
pub(crate) fn into_inline_with_anonymous_redaction(
117+
self,
118+
all_attribute_private: bool,
119+
global_private_attributes: HashSet<Reference>,
120+
) -> Self {
121+
Self {
122+
base: self.base.into_inline_with_anonymous_redaction(
123+
all_attribute_private,
124+
global_private_attributes,
125+
),
126+
..self
127+
}
128+
}
129+
}
130+
115131
impl Serialize for MigrationOpEvent {
116132
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
117133
where
@@ -120,7 +136,7 @@ impl Serialize for MigrationOpEvent {
120136
let mut state = serializer.serialize_struct("MigrationOpEvent", 10)?;
121137
state.serialize_field("kind", "migration_op")?;
122138
state.serialize_field("creationDate", &self.base.creation_date)?;
123-
state.serialize_field("contextKeys", &self.base.context.context_keys())?;
139+
state.serialize_field("context", &self.base.context)?;
124140
state.serialize_field("operation", &self.operation)?;
125141

126142
if !is_default_ratio(&self.sampling_ratio) {
@@ -369,6 +385,20 @@ pub struct CustomEvent {
369385
}
370386

371387
impl CustomEvent {
388+
pub(crate) fn into_inline_with_anonymous_redaction(
389+
self,
390+
all_attribute_private: bool,
391+
global_private_attributes: HashSet<Reference>,
392+
) -> Self {
393+
Self {
394+
base: self.base.into_inline_with_anonymous_redaction(
395+
all_attribute_private,
396+
global_private_attributes,
397+
),
398+
..self
399+
}
400+
}
401+
372402
pub fn to_index_event(
373403
&self,
374404
all_attribute_private: bool,

0 commit comments

Comments
 (0)