[][src]Struct tracing_opentelemetry::OpenTelemetryLayer

pub struct OpenTelemetryLayer<S, T: Tracer> { /* fields omitted */ }

OpenTelemetry layer for use in a project that uses tracing.

Methods

impl<S, T> OpenTelemetryLayer<S, T> where
    S: Subscriber + for<'span> LookupSpan<'span>,
    T: Tracer + 'static, 
[src]

pub fn with_tracer(tracer: T) -> Self[src]

Set the OpenTelemetry Tracer that this layer will use to produce and track Spans.

use opentelemetry::{api::Provider, global, sdk};
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;

// Create a jaeger exporter for a `trace-demo` service.
let exporter = opentelemetry_jaeger::Exporter::builder()
    .with_agent_endpoint("127.0.0.1:6831".parse().unwrap())
    .with_process(opentelemetry_jaeger::Process {
        service_name: "trace_demo".to_string(),
        tags: Vec::new(),
    })
    .init().expect("Error initializing Jaeger exporter");

// Build a provider from the jaeger exporter that always samples.
let provider = sdk::Provider::builder()
    .with_simple_exporter(exporter)
    .with_config(sdk::Config {
        default_sampler: Box::new(sdk::Sampler::Always),
        ..Default::default()
    })
    .build();

// Get a tracer from the provider for a component
let tracer = provider.get_tracer("component-name");

// Create a layer with the configured tracer
let otel_layer = OpenTelemetryLayer::with_tracer(tracer);

// Use the tracing subscriber `Registry`, or any other subscriber
// that impls `LookupSpan`
let _subscriber = Registry::default()
    .with(otel_layer);

Trait Implementations

impl<S, T> Layer<S> for OpenTelemetryLayer<S, T> where
    S: Subscriber + for<'span> LookupSpan<'span>,
    T: Tracer + 'static, 
[src]

fn new_span(&self, attrs: &Attributes, id: &Id, ctx: Context<S>)[src]

Creates an OpenTelemetry Span for the corresponding tracing Span. This will attempt to parse the parent context if possible from the given attributes.

fn on_record(&self, id: &Id, values: &Record, ctx: Context<S>)[src]

Record values for the given span.

fn on_event(&self, event: &Event, ctx: Context<S>)[src]

Record logs for the given event.

fn on_close(&self, id: Id, ctx: Context<S>)[src]

Mark the Span as ended when it is closed.

Auto Trait Implementations

impl<S, T> RefUnwindSafe for OpenTelemetryLayer<S, T> where
    S: RefUnwindSafe,
    T: RefUnwindSafe

impl<S, T> Send for OpenTelemetryLayer<S, T> where
    S: Send,
    T: Send

impl<S, T> Sync for OpenTelemetryLayer<S, T> where
    S: Sync,
    T: Sync

impl<S, T> Unpin for OpenTelemetryLayer<S, T> where
    S: Unpin,
    T: Unpin

impl<S, T> UnwindSafe for OpenTelemetryLayer<S, T> where
    S: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<F> Instrument for F[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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