Skip to main content

TelemetryBuilder

Struct TelemetryBuilder 

Source
pub struct TelemetryBuilder { /* private fields */ }
Available on crate feature otel only.
Expand description

Configures and builds a Telemetry; see Telemetry::builder.

Implementations§

Source§

impl TelemetryBuilder

Source

pub fn build(self) -> Result<Telemetry, TelemetryError>

Builds every signal that has an exporter, and its provider.

§Errors

TelemetryError for a value this crate cannot act on and cannot do without — an OTLP/HTTP endpoint with no scheme or that is not a URL, a certificate or key file that cannot be read, a client certificate without its key, a header name that is not one — named, with the value, except for headers; an exporter that cannot be built, a Prometheus address that cannot be listened on, or an export thread that cannot be started. Nothing is installed on error.

A value of an OTEL_* variable that is only wrong (an exporter name this SDK does not have, an unknown protocol or compression, a timeout or Prometheus port that is not a number) is not an error: the specification has an SDK warn and ignore it, so it is noted in Telemetry::notices with what was used instead, and the build goes on.

Source§

impl TelemetryBuilder

Source

pub const fn without_prometheus_listener(self) -> TelemetryBuilder

Available on crate feature otel-prometheus only.

Under OTEL_METRICS_EXPORTER=prometheus, binds no listener of its own: the application serves the text of Telemetry::prometheus on its own port, behind its own authentication and connection limits (audit C-16). OTEL_EXPORTER_PROMETHEUS_HOST and _PORT are then not read.

Source

pub const fn without_process_metrics(self) -> TelemetryBuilder

Reports no process or Tokio runtime metrics. By default, when metrics are exported, process.cpu.time, process.memory.usage, process.memory.virtual, process.thread.count and process.unix.file_descriptor.count are reported on Linux, and tokio.runtime.worker.count, tokio.runtime.task.count and tokio.runtime.global_queue.depth for the runtime build runs in (audit C-13).

Source

pub fn with_tokio_runtime(self, handle: Handle) -> TelemetryBuilder

Reports the Tokio runtime metrics of the runtime handle drives, instead of the one build runs in (if any). For an application that builds Telemetry before entering its runtime.

Source

pub const fn with_console_format( self, format: ConsoleFormat, ) -> TelemetryBuilder

The format install_subscriber prints in: text (the default) or one JSON object per line with trace_id, span_id and trace_flags inside a span (audit C-06). Wins over A2A_LOG_FORMAT (json or text), which applies when this is not called.

Source§

impl TelemetryBuilder

Source

pub fn with_default_service_name( self, name: impl Into<String>, ) -> TelemetryBuilder

The service.name to report when the environment names none. OTEL_SERVICE_NAME, or service.name in OTEL_RESOURCE_ATTRIBUTES, wins over it, as the OpenTelemetry environment specification has it — unlike init_otlp_pipeline’s argument.

Source

pub const fn with_traces(self, on: bool) -> TelemetryBuilder

Whether traces are exported when OTEL_TRACES_EXPORTER is unset (default: yes). The variable, otlp or none, wins.

Source

pub const fn with_metrics(self, on: bool) -> TelemetryBuilder

Whether metrics are exported when OTEL_METRICS_EXPORTER is unset (default: yes, or no with with_langfuse).

Source

pub const fn with_logs(self, on: bool) -> TelemetryBuilder

Whether tracing events are exported as OpenTelemetry log records when OTEL_LOGS_EXPORTER is unset (default: yes, or no with with_langfuse).

Source

pub const fn with_export_where_configured(self) -> TelemetryBuilder

Exports each signal only where an endpoint is configured for it: in code (with_otlp_endpoint, or with_langfuse for traces), or in OTEL_EXPORTER_OTLP_ENDPOINT, or in the signal’s own OTEL_EXPORTER_OTLP_TRACES_ENDPOINT / OTEL_EXPORTER_OTLP_METRICS_ENDPOINT / OTEL_EXPORTER_OTLP_LOGS_ENDPOINT. A signal with none is not built: no exporter, no export thread. For a binary that must run as well with a collector as without one; without this, every signal is exported, to localhost when nothing names an endpoint, as the OpenTelemetry environment specification has it.

with_traces and its siblings, set in code, still win, and OTEL_TRACES_EXPORTER and its siblings win over both.

Source

pub const fn with_log_level(self, level: Level) -> TelemetryBuilder

The least severe event exported as a log record (default INFO).

Source

pub const fn with_span_level(self, level: Level) -> TelemetryBuilder

The least severe span exported, and event recorded on one (default INFO, the level of every span this SDK makes).

Until 2026-10-29 spans had no level filter: every DEBUG and TRACE event of every crate in the process (h2’s frames, hyper’s, sqlx’s) that happened inside an exported span was exported as a span event, and RUST_LOG, which filters only what is printed, could not turn them off (audit C-01). Each layer now tells tracing its most verbose level, so callsites below it are not even evaluated.

Source

pub fn with_otlp_endpoint(self, base_url: impl Into<String>) -> TelemetryBuilder

The collector’s base URL for every signal, as OTEL_EXPORTER_OTLP_ENDPOINT would give it: OTLP/HTTP appends /v1/traces, /v1/metrics or /v1/logs. Set in code, it wins over the variable.

Source

pub const fn with_otlp_protocol( self, protocol: OtlpProtocol, ) -> TelemetryBuilder

The transport for every signal. Set in code, it wins over OTEL_EXPORTER_OTLP_PROTOCOL; unset, that variable decides, and HTTP/protobuf is the default.

Source

pub fn with_otlp_header( self, name: impl Into<String>, value: impl Into<String>, ) -> TelemetryBuilder

A header sent with every export, alongside OTEL_EXPORTER_OTLP_HEADERS.

Source

pub const fn with_compression( self, compression: OtlpCompression, ) -> TelemetryBuilder

Compresses every export body. OTEL_EXPORTER_OTLP_COMPRESSION (and the per-signal forms) asks for the same from the environment, and this wins over it. Code cannot turn off what the variable turned on: unset the variable, or set it to none. Without either, bodies are sent as they are.

Source

pub fn with_proxy(self, url: impl Into<String>) -> TelemetryBuilder

Sends every export through this HTTP proxy, as ALL_PROXY would, and wins over ALL_PROXY, HTTPS_PROXY and HTTP_PROXY. NO_PROXY does not apply to it: a proxy chosen in code is explicit, and does not change with the machine’s environment. Credentials go in the URL (http://user:pass@proxy:3128). Only http:// proxies are spoken; an https:// or socks5:// one is ignored with a warning, and the export goes direct.

Source

pub fn without_proxy(self) -> TelemetryBuilder

Sends exports straight to the collector, ignoring HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY. Without this, and without with_proxy, those variables apply as they do to curl.

Source

pub const fn without_resource_detection(self) -> TelemetryBuilder

Leaves the process’s own description out of the resource. By default it carries host.name, host.arch, os.type, process.pid and process.executable.name, each only when OTEL_RESOURCE_ATTRIBUTES does not name it; turn this off for an export to a party that should not learn them. service.name, service.instance.id and telemetry.sdk.* stay.

Source

pub const fn without_startup_summary(self) -> TelemetryBuilder

Leaves the startup line (describe()) out of what Telemetry::install_subscriber logs. By default it logs where each signal goes, or that nothing is exported and how to change that, once at INFO: what a server’s operator wants and a one-shot command-line tool does not, where it would be a line on standard error of every run. Warnings and errors (a lost export, a setting that was not honoured) are still printed, and describe() still returns the line.

Source

pub fn with_ca_certificate_pem(self, pem: impl AsRef<[u8]>) -> TelemetryBuilder

CA certificates, PEM, to trust alongside the bundled Mozilla roots — for a collector behind a private CA. OTEL_EXPORTER_OTLP_CERTIFICATE names a file of them and is read too.

Source

pub fn with_client_certificate_pem( self, cert_chain: impl AsRef<[u8]>, key: impl AsRef<[u8]>, ) -> TelemetryBuilder

A client certificate chain (leaf first) and its private key, PEM, presented to a collector that requires mutual TLS, over either transport. OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE and OTEL_EXPORTER_OTLP_CLIENT_KEY, or their per-signal forms, name files of them and win over this, as a variable wins over a header set in code. Both are checked when the exporters are built: a certificate or key that does not parse, or a key that is not the certificate’s on OTLP/HTTP, fails build.

Source

pub fn with_langfuse(self, langfuse: Langfuse) -> TelemetryBuilder

Sends traces to Langfuse; see Langfuse for exactly what it sets.

Source

pub const fn install_globally(self, on: bool) -> TelemetryBuilder

Whether to install the tracer and meter providers, and the W3C tracecontext and baggage propagators, as the process-global ones (default: yes). Off, nothing global changes — for a test, or a process with providers of its own.

Trait Implementations§

Source§

impl Debug for TelemetryBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more