Trait rama::telemetry::opentelemetry::trace::TracerProvider

pub trait TracerProvider {
    type Tracer: Tracer;

    // Required method
    fn library_tracer(
        &self,
        library: Arc<InstrumentationLibrary>,
    ) -> Self::Tracer;

    // Provided methods
    fn tracer(&self, name: impl Into<Cow<'static, str>>) -> Self::Tracer { ... }
    fn versioned_tracer(
        &self,
        name: impl Into<Cow<'static, str>>,
        version: Option<impl Into<Cow<'static, str>>>,
        schema_url: Option<impl Into<Cow<'static, str>>>,
        attributes: Option<Vec<KeyValue>>,
    ) -> Self::Tracer { ... }
    fn tracer_builder(
        &self,
        name: impl Into<Cow<'static, str>>,
    ) -> TracerBuilder<'_, Self> { ... }
}
Expand description

Types that can create instances of Tracer.

See the global module for examples of storing and retrieving tracer provider instances.

Required Associated Types§

type Tracer: Tracer

The Tracer type that this provider will return.

Required Methods§

fn library_tracer(&self, library: Arc<InstrumentationLibrary>) -> Self::Tracer

Returns a new versioned tracer with the given instrumentation library.

§Examples
use opentelemetry::{global, InstrumentationLibrary, trace::TracerProvider};

let provider = global::tracer_provider();

// tracer used in applications/binaries
let tracer = provider.tracer("my_app");

// tracer used in libraries/crates that optionally includes version and schema url
let library = std::sync::Arc::new(
    InstrumentationLibrary::builder(env!("CARGO_PKG_NAME"))
        .with_version(env!("CARGO_PKG_VERSION"))
        .with_schema_url("https://opentelemetry.io/schema/1.0.0")
        .build(),
);

let tracer = provider.library_tracer(library);

Provided Methods§

fn tracer(&self, name: impl Into<Cow<'static, str>>) -> Self::Tracer

Returns a new tracer with the given name.

The name should be the application name or the name of the library providing instrumentation. If the name is empty, then an implementation-defined default name may be used instead.

§Examples
use opentelemetry::{global, trace::TracerProvider};
use opentelemetry::KeyValue;

let provider = global::tracer_provider();

// tracer used in applications/binaries
let tracer = provider.tracer("my_app");

// tracer used in libraries/crates that optionally includes version and schema url
let tracer = provider.tracer_builder("my_library").
    with_version(env!("CARGO_PKG_VERSION")).
    with_schema_url("https://opentelemetry.io/schema/1.0.0").
    with_attributes([KeyValue::new("key", "value")]).
    build();

fn versioned_tracer( &self, name: impl Into<Cow<'static, str>>, version: Option<impl Into<Cow<'static, str>>>, schema_url: Option<impl Into<Cow<'static, str>>>, attributes: Option<Vec<KeyValue>>, ) -> Self::Tracer

👎Deprecated since 0.23.0: Please use tracer_builder() instead

Deprecated, use TracerProvider::tracer_builder()

Returns a new versioned tracer with a given name.

The name should be the application name or the name of the library providing instrumentation. If the name is empty, then an implementation-defined default name may be used instead.

§Examples
use opentelemetry::{global, trace::TracerProvider};

let provider = global::tracer_provider();

// tracer used in applications/binaries
let tracer = provider.tracer("my_app");

// tracer used in libraries/crates that optionally includes version and schema url
let tracer = provider.versioned_tracer(
    "my_library",
    Some(env!("CARGO_PKG_VERSION")),
    Some("https://opentelemetry.io/schema/1.0.0"),
    None,
);

fn tracer_builder( &self, name: impl Into<Cow<'static, str>>, ) -> TracerBuilder<'_, Self>

Returns a new builder for creating a Tracer instance

The name should be the application name or the name of the library providing instrumentation. If the name is empty, then an implementation-defined default name may be used instead.

§Examples
use opentelemetry::{global, trace::TracerProvider};

let provider = global::tracer_provider();

// tracer used in applications/binaries
let tracer = provider.tracer_builder("my_app").build();

// tracer used in libraries/crates that optionally includes version and schema url
let tracer = provider.tracer_builder("my_library")
    .with_version(env!("CARGO_PKG_VERSION"))
    .with_schema_url("https://opentelemetry.io/schema/1.0.0")
    .build();

Object Safety§

This trait is not object safe.

Implementors§