diff --git a/util/src/telemetry/datadog/formatter.rs b/util/src/telemetry/datadog/formatter.rs index b5239d21e..33bf55417 100644 --- a/util/src/telemetry/datadog/formatter.rs +++ b/util/src/telemetry/datadog/formatter.rs @@ -20,7 +20,7 @@ use tracing_opentelemetry::OtelData; use tracing_serde::AsSerde; use tracing_subscriber::fmt::format::Writer; -use tracing_subscriber::fmt::{FmtContext, FormatEvent, FormatFields}; +use tracing_subscriber::fmt::{FmtContext, FormatEvent, FormatFields, FormattedFields}; use tracing_subscriber::registry::{LookupSpan, SpanRef}; /// A trace or span ID in the format expected by Datadog @@ -122,6 +122,18 @@ where serializer = visitor.take_serializer()?; if let Some(ref span_ref) = ctx.lookup_current() { + // Record current span fields, inspired by https://github.com/tokio-rs/tracing/blob/tracing-subscriber-0.3.19/tracing-subscriber/src/fmt/format/json.rs#L168-L207 + if let Some(fmt_fields) = span_ref.extensions().get::>() { + if let Ok(serde_json::Value::Object(fields)) = + serde_json::from_str::(fmt_fields) + { + for (key, value) in fields { + serializer.serialize_entry(&key, &value)?; + } + } + } + + // Record trace ID and span ID, if present if let Some(trace_info) = lookup_trace_info(span_ref) { serializer.serialize_entry("dd.span_id", &trace_info.span_id)?; serializer.serialize_entry("dd.trace_id", &trace_info.trace_id)?; diff --git a/workers/job-types/src/event_manager.rs b/workers/job-types/src/event_manager.rs index 55123c7c7..fd2d22cf7 100644 --- a/workers/job-types/src/event_manager.rs +++ b/workers/job-types/src/event_manager.rs @@ -58,6 +58,47 @@ pub enum RelayerEvent { ExternalMatch(ExternalMatchEvent), } +impl RelayerEvent { + /// Returns the event ID + pub fn event_id(&self) -> Uuid { + match self { + RelayerEvent::WalletCreation(event) => event.event_id, + RelayerEvent::ExternalTransfer(event) => event.event_id, + RelayerEvent::OrderPlacement(event) => event.event_id, + RelayerEvent::OrderUpdate(event) => event.event_id, + RelayerEvent::OrderCancellation(event) => event.event_id, + RelayerEvent::Match(event) => event.event_id, + RelayerEvent::ExternalMatch(event) => event.event_id, + } + } + + /// Returns the event timestamp + pub fn event_timestamp(&self) -> SystemTime { + match self { + RelayerEvent::WalletCreation(event) => event.event_timestamp, + RelayerEvent::ExternalTransfer(event) => event.event_timestamp, + RelayerEvent::OrderPlacement(event) => event.event_timestamp, + RelayerEvent::OrderUpdate(event) => event.event_timestamp, + RelayerEvent::OrderCancellation(event) => event.event_timestamp, + RelayerEvent::Match(event) => event.event_timestamp, + RelayerEvent::ExternalMatch(event) => event.event_timestamp, + } + } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + match self { + RelayerEvent::WalletCreation(event) => event.describe(), + RelayerEvent::ExternalTransfer(event) => event.describe(), + RelayerEvent::OrderPlacement(event) => event.describe(), + RelayerEvent::OrderUpdate(event) => event.describe(), + RelayerEvent::OrderCancellation(event) => event.describe(), + RelayerEvent::Match(event) => event.describe(), + RelayerEvent::ExternalMatch(event) => event.describe(), + } + } +} + // -------------------------- // | Individual Event Types | // -------------------------- @@ -82,6 +123,11 @@ impl WalletCreationEvent { let (event_id, event_timestamp) = get_event_id_and_timestamp(); Self { event_id, event_timestamp, wallet_id, symmetric_key } } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + format!("WalletCreation({})", self.event_id) + } } /// An external transfer event @@ -104,6 +150,11 @@ impl ExternalTransferEvent { let (event_id, event_timestamp) = get_event_id_and_timestamp(); Self { event_id, event_timestamp, wallet_id, transfer } } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + format!("ExternalTransfer({})", self.event_id) + } } /// An order placement event @@ -135,6 +186,11 @@ impl OrderPlacementEvent { let (event_id, event_timestamp) = get_event_id_and_timestamp(); Self { event_id, event_timestamp, wallet_id, order_id, order, matching_pool } } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + format!("OrderPlacement({})", self.event_id) + } } /// An order update event @@ -166,6 +222,11 @@ impl OrderUpdateEvent { let (event_id, event_timestamp) = get_event_id_and_timestamp(); Self { event_id, event_timestamp, wallet_id, order_id, order, matching_pool } } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + format!("OrderUpdate({})", self.event_id) + } } /// An order cancellation event @@ -208,6 +269,11 @@ impl OrderCancellationEvent { amount_filled, } } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + format!("OrderCancellation({})", self.event_id) + } } /// A match event @@ -276,6 +342,11 @@ impl MatchEvent { fee_take1, } } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + format!("Match({})", self.event_id) + } } /// An external match event @@ -327,6 +398,11 @@ impl ExternalMatchEvent { external_fee_take, } } + + /// Returns a human-readable description of the event + pub fn describe(&self) -> String { + format!("ExternalMatch({})", self.event_id) + } } // -----------