Skip to main content

OtelTracer

Struct OtelTracer 

Source
pub struct OtelTracer { /* private fields */ }
Expand description

A compatibility wrapper that exposes the same Tracer interface as the OpenTelemetry SDK but is implemented internally by delegating every call to a SzTracer.

§What this is (and is not)

This type exists so that downstream code can be written against an “otel-style” tracer name without pulling in the real opentelemetry crate as a dependency. It is not a real OpenTelemetry implementation:

  • It does not export spans to an OTLP / Jaeger / Zipkin collector.
  • v0.2.2 修复 P2-2:现已实现 W3C TraceContext traceparent header 传播00-<trace_id>-<span_id>-<trace_flags>),同时保留 parent-span-id header 以传递父 span 关系。extract 优先解析 W3C,回退到 legacy。
  • It does not perform sampling, baggage propagation, or context extraction across async boundaries.
  • Span IDs are generated from std::collections::hash_map::RandomState rather than per the OpenTelemetry specification (16 hex chars / 8 bytes random).

§When to use which

  • Use SzTracer directly for in-process span collection and W3C TraceContext header propagation.
  • Use OtelTracer when an existing code base expects a tracer whose name signals OpenTelemetry-compatibility, but you have already decided to back it with SzTracer semantics.
  • For production distributed tracing across service boundaries, depend on the real opentelemetry SDK and use its Tracer implementation instead.

Both SzTracer and OtelTracer satisfy the Tracer trait, so they can be swapped at the type level without changing call sites.

Implementations§

Source§

impl OtelTracer

Source

pub fn new(service_name: impl Into<String>) -> OtelTracer

Wraps a freshly-built SzTracer tagged with service_name.

Source

pub fn inner(&self) -> &SzTracer

Provides read access to the underlying SzTracer so callers can inspect accumulated spans or clear them between tests.

Trait Implementations§

Source§

impl Tracer for OtelTracer

Source§

fn start_span(&self, operation_name: &str) -> Span

Source§

fn end_span(&self, span: Span)

Source§

fn inject(&self, span: &Span) -> HashMap<String, String>

Source§

fn extract(&self, headers: &HashMap<String, String>) -> Option<Span>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more