pub struct Telemetry { /* private fields */ }Expand description
Unified telemetry management for traces, metrics, and logs.
This struct holds the OpenTelemetry providers and ensures proper shutdown when dropped. Create an instance at application startup and keep it alive for the duration of your application.
§Lifecycle
- Create at application startup using
Telemetry::new()orTelemetry::builder() - Keep the instance alive (e.g., in your main function or as application state)
- Providers automatically shut down when
Telemetryis dropped - For explicit shutdown control, call
Telemetry::shutdown()
§Example
use apollo_opentelemetry::{OpenTelemetryConfig, Telemetry};
// Initialize at startup
let telemetry = Telemetry::new(OpenTelemetryConfig::default())?;
// Access providers if needed
if let Some(tracer_provider) = telemetry.tracer_provider() {
// Use the tracer provider directly
}
// Telemetry shuts down automatically when droppedImplementations§
Source§impl Telemetry
impl Telemetry
Sourcepub fn none() -> Self
pub fn none() -> Self
Create a no-op telemetry instance with no providers or output.
This returns a Telemetry instance that does nothing: no providers
are created, no global providers are set, and no data is exported.
This is useful for:
- Tests: When you need a
Telemetryinstance but don’t want actual telemetry overhead or output. - Disabled telemetry: When you want to completely disable telemetry without going through configuration parsing.
Sourcepub fn builder(config: OpenTelemetryConfig) -> TelemetryBuilder
pub fn builder(config: OpenTelemetryConfig) -> TelemetryBuilder
Create a builder for configuring telemetry.
Use the builder when you need to add custom exporters, processors, or views programmatically.
§Example
use apollo_opentelemetry::{OpenTelemetryConfig, Telemetry};
let telemetry = Telemetry::builder(OpenTelemetryConfig::default())
.with_global_tracer_provider()
.build()?;Sourcepub fn new(config: OpenTelemetryConfig) -> Result<Self, InitError>
pub fn new(config: OpenTelemetryConfig) -> Result<Self, InitError>
Create telemetry with full integration from configuration.
This method sets up OpenTelemetry with all integrations enabled:
- Global tracer provider: Enables
opentelemetry::global::tracer()anywhere - Global meter provider: Enables
opentelemetry::global::meter()anywhere - Log bridge: Routes
log::info!()etc. to OpenTelemetry logs - Tracing bridge: Routes
tracing::info!()etc. to OpenTelemetry logs
This is the recommended way to initialize telemetry for most applications, as it provides seamless integration with the Rust logging ecosystem.
§When to use builder() instead
Use Telemetry::builder() if you need:
- Custom exporters or processors
- To disable specific bridges (e.g., if you have your own tracing subscriber)
- Fine-grained control over which integrations are enabled
§Effects on your application
- Sets the global logger: Only one logger can be set per process. This will
fail if another logger (e.g.,
env_logger) is already installed. - Sets the global tracing subscriber: Only one subscriber can be set per process. This will fail if another subscriber is already installed.
- Filters apply: Both bridges respect
RUST_LOGfor filtering (defaults toinfo).
§Example
use apollo_opentelemetry::{OpenTelemetryConfig, Telemetry};
let config = OpenTelemetryConfig::default();
let telemetry = Telemetry::new(config)?;
// Now all logging goes through OpenTelemetry
log::info!("This becomes an OpenTelemetry log record");Sourcepub fn tracer_provider(&self) -> Option<&SdkTracerProvider>
pub fn tracer_provider(&self) -> Option<&SdkTracerProvider>
Get a reference to the tracer provider, if tracing is enabled.
Returns None if no tracer configuration was provided and no
span exporters were added programmatically.
Sourcepub fn meter_provider(&self) -> Option<&SdkMeterProvider>
pub fn meter_provider(&self) -> Option<&SdkMeterProvider>
Get a reference to the meter provider, if metrics are enabled.
Returns None if no meter configuration was provided and no
metric views were added programmatically.
Sourcepub fn logger_provider(&self) -> Option<&SdkLoggerProvider>
pub fn logger_provider(&self) -> Option<&SdkLoggerProvider>
Get a reference to the logger provider, if logging is enabled.
Returns None if no logger configuration was provided and no
log exporters were added programmatically.
Sourcepub fn shutdown(&mut self)
pub fn shutdown(&mut self)
Explicitly shut down all telemetry providers.
This flushes any buffered telemetry data and releases resources.
It is called automatically when the Telemetry instance is dropped,
but can be called explicitly for more control over shutdown timing.
If the providers were registered as global providers, the global provider will continue to reference the shut-down provider, which will act as a no-op for any subsequent operations.
After calling shutdown(), the providers are no longer available
and subsequent calls to tracer_provider(), meter_provider(),
and logger_provider() will return None.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Telemetry
impl !UnwindSafe for Telemetry
impl Freeze for Telemetry
impl Send for Telemetry
impl Sync for Telemetry
impl Unpin for Telemetry
impl UnsafeUnpin for Telemetry
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
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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more