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::*;