pub struct TracerGuard { /* private fields */ }Expand description
The tracer provider setup_tracer registered. Dropping the guard flushes the provider;
shutdown flushes and stops it.
Every call of setup_tracer returns a guard; the guards of repeat calls share the first
call’s provider. Shutting any of them down stops that provider for all and clears the
registration, so the next setup_tracer builds and registers a new one.
Implementations§
Source§impl TracerGuard
impl TracerGuard
Sourcepub fn layer<S>(&self) -> OpenTelemetryLayer<S, SdkTracer>where
S: Subscriber + for<'span> LookupSpan<'span>,
pub fn layer<S>(&self) -> OpenTelemetryLayer<S, SdkTracer>where
S: Subscriber + for<'span> LookupSpan<'span>,
The tracing layer that exports the agent’s spans through the provider. Add it to the
application’s subscriber, or let try_init_subscriber do it.
The layer does not export the code location, target, thread or busy/idle time attributes
tracing-opentelemetry adds by default, so spans carry the SDK’s attributes only. The SDK’s
spans are INFO spans with target strands::telemetry: a filter in front of the layer
(an EnvFilter on the registry, for example) must let them through, or the layer exports
nothing. Give the layer its own filter instead to keep other layers quieter:
use strands::telemetry::tracing_subscriber::filter::LevelFilter;
use strands::telemetry::tracing_subscriber::layer::{Layer, SubscriberExt};
use strands::telemetry::tracing_subscriber::util::SubscriberInitExt;
use strands::telemetry::{TelemetryExporters, TracerConfig, setup_tracer};
let telemetry = setup_tracer(TracerConfig {
exporters: TelemetryExporters { otlp: true, console: false },
..Default::default()
})?;
strands::telemetry::tracing_subscriber::registry()
.with(telemetry.layer())
.with(strands::telemetry::tracing_subscriber::fmt::layer().with_filter(LevelFilter::WARN))
.init();Sourcepub fn try_init_subscriber(&self) -> Result<()>
pub fn try_init_subscriber(&self) -> Result<()>
Installs a global subscriber with only layer, for programs that have no
subscriber of their own; any other layers belong on a registry the program builds.
use strands::telemetry::{TelemetryExporters, TracerConfig, setup_tracer};
let telemetry = setup_tracer(TracerConfig {
exporters: TelemetryExporters { otlp: true, console: false },
..Default::default()
})?;
telemetry.try_init_subscriber()?;§Errors
A global subscriber is already set.
Trait Implementations§
Source§impl Debug for TracerGuard
impl Debug for TracerGuard
Source§impl Drop for TracerGuard
impl Drop for TracerGuard
Auto Trait Implementations§
impl !RefUnwindSafe for TracerGuard
impl !UnwindSafe for TracerGuard
impl Freeze for TracerGuard
impl Send for TracerGuard
impl Sync for TracerGuard
impl Unpin for TracerGuard
impl UnsafeUnpin for TracerGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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