Struct opentelemetry_sdk::trace::TracerProvider
source · pub struct TracerProvider { /* private fields */ }
Expand description
Creator and registry of named Tracer
instances.
TracerProvider
is lightweight container holding pointers to SpanProcessor
and other components.
Cloning and dropping them will not stop the span processing. To stop span processing, users
must either call shutdown
method explicitly, or drop every clone of TracerProvider
.
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
source§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
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
Create a new versioned Tracer
instance.
source§fn library_tracer(&self, library: Arc<InstrumentationLibrary>) -> Self::Tracer
fn library_tracer(&self, library: Arc<InstrumentationLibrary>) -> Self::Tracer
Returns a new versioned tracer with the given instrumentation library. Read more
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default 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,
library: Arc<InstrumentationLibrary>,
) -> Box<dyn ObjectSafeTracer + Sync + Send>
fn boxed_tracer( &self, library: Arc<InstrumentationLibrary>, ) -> Box<dyn ObjectSafeTracer + Sync + Send>
Return a versioned boxed tracer