diff --git a/libs/telemetry/src/capturing/ng/collector.rs b/libs/telemetry/src/capturing/ng/collector.rs index e4c7fdb34a7..3dff5ed6a91 100644 --- a/libs/telemetry/src/capturing/ng/collector.rs +++ b/libs/telemetry/src/capturing/ng/collector.rs @@ -1,6 +1,6 @@ use std::{borrow::Cow, collections::HashMap, num::NonZeroU64, sync::Arc}; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use tokio::time::Instant; use tracing::Level; @@ -21,6 +21,19 @@ impl Serialize for SerializableNonZeroU64 { } } +impl<'de> Deserialize<'de> for SerializableNonZeroU64 { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let value = String::deserialize(deserializer)?; + let value = value.parse().map_err(serde::de::Error::custom)?; + Ok(SerializableNonZeroU64( + NonZeroU64::new(value).ok_or_else(|| serde::de::Error::custom("value must be non-zero"))?, + )) + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] pub struct SpanId(SerializableNonZeroU64);