From f83c1dd7ee57000a4734454519b333e18e236a91 Mon Sep 17 00:00:00 2001 From: Lalit Date: Sat, 26 Oct 2024 12:55:12 -0700 Subject: [PATCH] bring back PropagationError, will cleanup separately --- opentelemetry/src/propagation/mod.rs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/opentelemetry/src/propagation/mod.rs b/opentelemetry/src/propagation/mod.rs index 9c85936b0f..35005f881a 100644 --- a/opentelemetry/src/propagation/mod.rs +++ b/opentelemetry/src/propagation/mod.rs @@ -62,6 +62,37 @@ impl Extractor for HashMap { } } +/// Error when extracting or injecting context data(i.e propagating) across application boundaries. +#[derive(Error, Debug)] +#[error("Cannot {} from {}, {}", ops, message, propagator_name)] +pub struct PropagationError { + message: &'static str, + // which propagator does this error comes from + propagator_name: &'static str, + // are we extracting or injecting information across application boundaries + ops: &'static str, +} + +impl PropagationError { + /// Error happens when extracting information + pub fn extract(message: &'static str, propagator_name: &'static str) -> Self { + PropagationError { + message, + propagator_name, + ops: "extract", + } + } + + /// Error happens when extracting information + pub fn inject(message: &'static str, propagator_name: &'static str) -> Self { + PropagationError { + message, + propagator_name, + ops: "inject", + } + } +} + #[cfg(test)] mod tests { use super::*;