Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions crates/common/common_utils/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,18 @@ impl EventStage {
pub struct KafkaTopicConfig {
pub topic: String,
pub partition_key_field: String,
#[serde(default)]
pub payload_format: EventPayloadFormat,
}

#[derive(
Debug, Clone, Copy, Default, Deserialize, Serialize, PartialEq, config_patch_derive::Patch,
)]
#[serde(rename_all = "snake_case")]
pub enum EventPayloadFormat {
#[default]
Json,
JsonString,
}

/// Configuration for events system
Expand Down Expand Up @@ -614,9 +626,29 @@ pub(crate) fn process_event_with_config(
}
}

if config.topic_config(&event.stage).payload_format == EventPayloadFormat::JsonString {
stringify_event_payloads(&mut result);
}

Ok(result)
}

fn stringify_event_payloads(result: &mut serde_json::Value) {
let Some(obj) = result.as_object_mut() else {
return;
};

for field in ["request_data", "response_data", "error"] {
let Some(value) = obj.get_mut(field) else {
continue;
};

if !value.is_null() && !value.is_string() {
*value = serde_json::Value::String(value.to_string());
}
}
}

pub(crate) fn extract_from_request(
event_value: &serde_json::Value,
extraction_path: &str,
Expand Down
Loading