Skip to main content

SzTracer

Struct SzTracer 

Source
pub struct SzTracer { /* private fields */ }

Implementations§

Source§

impl SzTracer

Source

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

Source

pub fn generate_trace_id() -> String

Source

pub fn generate_span_id() -> String

Source

pub fn get_spans(&self) -> Vec<Span>

Source

pub fn clear(&self)

Source§

impl SzTracer

Source

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

注入 legacy 自定义 header(向后兼容)

v0.2.2 修复 P2-2:保留旧版 header 格式以兼容旧客户端。 新代码应使用 Tracer::inject(W3C TraceContext)。

Source

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

仅从 legacy header 中提取 Span(向后兼容)

v0.2.2 修复 P2-2:保留旧版 header 解析以兼容旧客户端。 新代码应使用 Tracer::extract(自动优先 W3C,回退 legacy)。

Trait Implementations§

Source§

impl Default for SzTracer

Source§

fn default() -> SzTracer

Returns the “default value” for a type. Read more
Source§

impl Tracer for SzTracer

Source§

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

注入 W3C TraceContext traceparent header

v0.2.2 修复 P2-2:从自定义 trace-id/span-id/parent-span-id header 升级为 W3C TraceContext 标准的 traceparent header。

格式:00-<trace_id>-<span_id>-<trace_flags>

  • 00:版本号(W3C 规范固定为 00
  • trace_id:32 字符 hex(16 字节)
  • span_id:16 字符 hex(8 字节)
  • trace_flags:2 字符 hex(01 表示 sampled,00 表示未采样)

同时保留 parent-span-id header 以向后兼容旧版本的 extract。

Source§

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

从 headers 中提取 Span

v0.2.2 修复 P2-2:优先解析 W3C TraceContext traceparent header, 若不存在则回退到 legacy 自定义 header(trace-id/span-id)。

W3C traceparent 格式:00-<trace_id>-<span_id>-<trace_flags>

  • 版本号必须为 00
  • trace_id 必须为 32 字符 hex
  • span_id 必须为 16 字符 hex
  • trace_flags 必须为 2 字符 hex
Source§

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

Source§

fn end_span(&self, span: 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