[][src]Trait opentracingrust::ImplContext

pub trait ImplContext: Send {
    fn impl_context(&self) -> &dyn Any;
fn clone(&self) -> Box<dyn ImplContext>;
fn reference_span(&mut self, reference: &SpanReference); }

Tracer implementation's context details.

An OpenTracing SpanContext is an abstraction that holds:

  • Baggage items: key-value pairs that are propagated though the trace.
  • Tracer specific details: such as the trace and span ids, flags, and other information that are needed by the concrete tracer (Zipkin, Jaeger, ...).

OpenTracingRust splits this abstraction into two:

  • The SpanContext structure: holding all the common data.
  • The ImplContext trait: holding implementation details.

Implementations of ImplContext are only used by implementations of the TracerInterface and are carried around by the SpanContext. They contain span and trace identifiers and Tracer specific metadata.

Examples

extern crate opentracingrust;

use std::any::Any;
use opentracingrust::ImplContext;
use opentracingrust::SpanContext;
use opentracingrust::SpanReference;


pub struct SomeTracerContext {
    span_id: u64,
    trace_id: u64,
}

impl ImplContext for SomeTracerContext {
    fn impl_context(&self) -> &Any {
        self
    }

    fn clone(&self) -> Box<ImplContext> {
        Box::new(SomeTracerContext {
            span_id: self.span_id,
            trace_id: self.trace_id,
        })
    }

    fn reference_span(&mut self, reference: &SpanReference) {
        match *reference {
            SpanReference::ChildOf(ref parent) |
            SpanReference::FollowsFrom(ref parent) => {
                let context = parent.impl_context::<SomeTracerContext>().unwrap();
                self.trace_id = context.trace_id;
            }
        }
    }
}

fn main() {
    // ... snip ...

    let span_context = SpanContext::new(SomeTracerContext {
        span_id: 21,
        trace_id: 42,
    });

    // ... snip ...
}

Required methods

fn impl_context(&self) -> &dyn Any

Allow runtime downcasting with the Any interface.

SpanContexts store implementations ImplContexts using Boxes.
This method is used by the SpanContext::impl_context generic method to downcast the boxed ImplContext using the std::any::Any interface.

fn clone(&self) -> Box<dyn ImplContext>

Clones an ImplContext trait object into a new ImplContext trait object.

fn reference_span(&mut self, reference: &SpanReference)

Allows the ImplContext to add references.

When a reference is added to a SpanContext this method will be called so that the tracer's ImplContext can update its internal references.

Loading content...

Implementors

impl<T: Any + Clone + Send + SpanReferenceAware> ImplContext for ImplContextBox<T>[src]

Loading content...