hyperlane-plugin-tracing 22.14.1

A lock-free W3C Trace Context (traceparent/tracestate), X-Request-Id, Server-Timing, and pluggable SpanExporter distributed tracing plugin for the Hyperlane framework.
Documentation
/// Standard W3C Trace Context `traceparent` header name.
pub const HEADER_TRACEPARENT: &str = "traceparent";

/// Standard W3C Trace Context `tracestate` header name.
pub const HEADER_TRACESTATE: &str = "tracestate";

/// Context attribute key storing the active [`crate::TraceContext`].
pub const ATTR_TRACE_CONTEXT: &str = "hyperlane_plugin_tracing_context";

/// Preformatted internal map key for zero-clone borrowed lookup of [`crate::TraceContext`].
pub(crate) const ATTR_TRACE_CONTEXT_MAP_KEY: &str =
    "External(\"hyperlane_plugin_tracing_context\")";

/// Preformatted internal map key for zero-clone borrowed lookup of request start `Instant`.
pub(crate) const ATTR_TRACE_STARTED_AT_MAP_KEY: &str =
    "External(\"hyperlane_plugin_tracing_started_at\")";

/// W3C Trace Context version `00`.
pub(crate) const TRACEPARENT_VERSION: &str = "00";

/// Exact byte length of a canonical W3C `traceparent` header value (`00-<32>-<16>-<2>`).
pub(crate) const TRACEPARENT_LEN: usize = 55;

/// Invalid W3C `traceparent` version byte (`0xff`).
pub(crate) const TRACEPARENT_INVALID_VERSION: u8 = 0xFF;

/// W3C trace flags byte value indicating sampled (`01`).
pub(crate) const TRACE_FLAGS_SAMPLED: &str = "01";

/// W3C trace flags byte value indicating not sampled (`00`).
pub(crate) const TRACE_FLAGS_UNSAMPLED: &str = "00";

/// Default `Server-Timing` metric label.
pub(crate) const DEFAULT_SERVER_TIMING_LABEL: &str = "app";

/// `Server-Timing` duration parameter separator.
pub(crate) const SERVER_TIMING_DUR_PREFIX: &str = ";dur=";

/// Stack buffer capacity for formatting `Server-Timing` without heap allocation.
pub(crate) const SERVER_TIMING_STACK_CAP: usize = 128;

/// Lowercase hexadecimal alphabet used for fast stack-allocated trace/span formatting.
pub(crate) const HEX_DIGITS: &[u8; 16] = b"0123456789abcdef";

/// Invalid marker stored in [`HEX_DECODE_TABLE`] for non-hexadecimal bytes.
pub(crate) const HEX_INVALID: u8 = 0xFF;

/// Branchless ASCII hexadecimal lookup table mapping `'0'..='9'`, `'a'..='f'`, `'A'..='F'` to `0..=15` and others to `0xFF`.
pub(crate) const HEX_DECODE_TABLE: [u8; 256] = {
    let mut table: [u8; 256] = [HEX_INVALID; 256];
    let mut b: usize = 0;
    while b < 10 {
        table[b'0' as usize + b] = b as u8;
        b += 1;
    }
    let mut c: usize = 0;
    while c < 6 {
        table[b'a' as usize + c] = (10 + c) as u8;
        table[b'A' as usize + c] = (10 + c) as u8;
        c += 1;
    }
    table
};

/// SplitMix64 Weyl increment constant.
pub(crate) const SPLITMIX_GAMMA: u64 = 0x9E37_79B9_7F4A_7C15;

/// SplitMix64 first mixing multiplier.
pub(crate) const SPLITMIX_MUL1: u64 = 0xBF58_476D_1CE4_E5B9;

/// SplitMix64 second mixing multiplier.
pub(crate) const SPLITMIX_MUL2: u64 = 0x94D0_49BB_1331_11EB;