hyperlane-plugin-tracing 23.3.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\")";

/// Context attribute key storing request start `Instant`.
pub(crate) const ATTR_TRACE_STARTED_AT: &str = "hyperlane_plugin_tracing_started_at";

/// 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;

/// ASCII hyphen byte separating W3C `traceparent` fields.
pub(crate) const BYTE_DASH: u8 = b'-';

/// Hyphen character separating W3C `traceparent` fields.
pub(crate) const CHAR_DASH: char = '-';

/// ASCII decimal point byte used in `Server-Timing` durations.
pub(crate) const BYTE_DOT: u8 = b'.';

/// ASCII `'0'` byte used for decimal formatting.
pub(crate) const BYTE_ZERO: u8 = b'0';

/// 256-entry 2-byte lowercase hexadecimal lookup table for fast trace/span ID formatting.
pub(crate) const HEX_ENCODE_PAIRS: [[u8; 2]; 256] = {
    const DIGITS: &[u8; 16] = b"0123456789abcdef";
    let mut table: [[u8; 2]; 256] = [[0u8; 2]; 256];
    let mut i: usize = 0;
    while i < 256 {
        table[i] = [DIGITS[i >> 4], DIGITS[i & 0x0F]];
        i += 1;
    }
    table
};

/// 100-entry 2-digit ASCII decimal lookup table (`"00"`..`"99"`) for fast `Server-Timing` formatting.
pub(crate) const DEC_DIGITS_LUT: [[u8; 2]; 100] = {
    let mut table: [[u8; 2]; 100] = [[b'0'; 2]; 100];
    let mut i: usize = 0;
    while i < 100 {
        table[i] = [b'0' + (i / 10) as u8, b'0' + (i % 10) as u8];
        i += 1;
    }
    table
};

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

/// Flag bit set in [`HEX_DECODE_TABLE`] for uppercase `'A'..='F'` hexadecimal bytes.
pub(crate) const HEX_UPPER_BIT: u8 = 0x10;

/// Branchless ASCII hexadecimal lookup table mapping `'0'..='9'`, `'a'..='f'` to `0..=15`, `'A'..='F'` to `(10..=15) | 0x10`, 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) | HEX_UPPER_BIT;
        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;