pub struct TracerProvider { /* private fields */ }
Expand description
Creator and registry of named Tracer
instances.
TracerProvider
is a container holding pointers to SpanProcessor
and other components.
Cloning a TracerProvider
instance and dropping it will not stop span processing. To stop span processing, users
must either call the shutdown
method explicitly or allow the last reference to the TracerProvider
to be dropped. When the last reference is dropped, the shutdown process will be automatically triggered
to ensure proper cleanup.
Implementations§
source§impl TracerProvider
impl TracerProvider
sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Create a new TracerProvider
builder.
sourcepub fn force_flush(&self) -> Vec<TraceResult<()>>
pub fn force_flush(&self) -> Vec<TraceResult<()>>
Force flush all remaining spans in span processors and return results.
§Examples
use opentelemetry::global;
use opentelemetry_sdk::trace::TracerProvider;
fn init_tracing() -> TracerProvider {
let provider = TracerProvider::default();
// Set provider to be used as global tracer provider
let _ = global::set_tracer_provider(provider.clone());
provider
}
fn main() {
let provider = init_tracing();
// create spans..
// force all spans to flush
for result in provider.force_flush() {
if let Err(err) = result {
// .. handle flush error
}
}
// create more spans..
// dropping provider and shutting down global provider ensure all
// remaining spans are exported
drop(provider);
global::shutdown_tracer_provider();
}
sourcepub fn shutdown(&self) -> TraceResult<()>
pub fn shutdown(&self) -> TraceResult<()>
Shuts down the current TracerProvider
.
Note that shut down doesn’t means the TracerProvider has dropped
Trait Implementations§
source§impl Clone for TracerProvider
impl Clone for TracerProvider
source§fn clone(&self) -> TracerProvider
fn clone(&self) -> TracerProvider
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for TracerProvider
impl Debug for TracerProvider
source§impl Default for TracerProvider
impl Default for TracerProvider
source§impl TracerProvider for TracerProvider
impl TracerProvider for TracerProvider
Auto Trait Implementations§
impl Freeze for TracerProvider
impl !RefUnwindSafe for TracerProvider
impl Send for TracerProvider
impl Sync for TracerProvider
impl Unpin for TracerProvider
impl !UnwindSafe for TracerProvider
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<S, T, P> ObjectSafeTracerProvider for P
impl<S, T, P> ObjectSafeTracerProvider for P
source§fn boxed_tracer(
&self,
scope: InstrumentationScope,
) -> Box<dyn ObjectSafeTracer + Sync + Send>
fn boxed_tracer( &self, scope: InstrumentationScope, ) -> Box<dyn ObjectSafeTracer + Sync + Send>
Return a versioned boxed tracer