pub struct TelemetryBuilder { /* private fields */ }otel only.Expand description
Configures and builds a Telemetry; see Telemetry::builder.
Implementations§
Source§impl TelemetryBuilder
impl TelemetryBuilder
Sourcepub fn build(self) -> Result<Telemetry, TelemetryError>
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
impl TelemetryBuilder
Sourcepub const fn without_prometheus_listener(self) -> TelemetryBuilder
Available on crate feature otel-prometheus only.
pub const fn without_prometheus_listener(self) -> TelemetryBuilder
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.
Sourcepub const fn without_process_metrics(self) -> TelemetryBuilder
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).
Sourcepub fn with_tokio_runtime(self, handle: Handle) -> TelemetryBuilder
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.
Sourcepub const fn with_console_format(
self,
format: ConsoleFormat,
) -> TelemetryBuilder
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
impl TelemetryBuilder
Sourcepub fn with_default_service_name(
self,
name: impl Into<String>,
) -> TelemetryBuilder
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.
Sourcepub const fn with_traces(self, on: bool) -> TelemetryBuilder
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.
Sourcepub const fn with_metrics(self, on: bool) -> TelemetryBuilder
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).
Sourcepub const fn with_logs(self, on: bool) -> TelemetryBuilder
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).
Sourcepub const fn with_export_where_configured(self) -> TelemetryBuilder
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.
Sourcepub const fn with_log_level(self, level: Level) -> TelemetryBuilder
pub const fn with_log_level(self, level: Level) -> TelemetryBuilder
The least severe event exported as a log record (default INFO).
Sourcepub const fn with_span_level(self, level: Level) -> TelemetryBuilder
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.
Sourcepub fn with_otlp_endpoint(self, base_url: impl Into<String>) -> TelemetryBuilder
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.
Sourcepub const fn with_otlp_protocol(
self,
protocol: OtlpProtocol,
) -> TelemetryBuilder
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.
Sourcepub fn with_otlp_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> TelemetryBuilder
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.
Sourcepub const fn with_compression(
self,
compression: OtlpCompression,
) -> TelemetryBuilder
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.
Sourcepub fn with_proxy(self, url: impl Into<String>) -> TelemetryBuilder
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.
Sourcepub fn without_proxy(self) -> TelemetryBuilder
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.
Sourcepub const fn without_resource_detection(self) -> TelemetryBuilder
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.
Sourcepub const fn without_startup_summary(self) -> TelemetryBuilder
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.
Sourcepub fn with_ca_certificate_pem(self, pem: impl AsRef<[u8]>) -> TelemetryBuilder
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.
Sourcepub fn with_client_certificate_pem(
self,
cert_chain: impl AsRef<[u8]>,
key: impl AsRef<[u8]>,
) -> TelemetryBuilder
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.
Sourcepub fn with_langfuse(self, langfuse: Langfuse) -> TelemetryBuilder
pub fn with_langfuse(self, langfuse: Langfuse) -> TelemetryBuilder
Sends traces to Langfuse; see Langfuse for exactly what it sets.
Sourcepub const fn install_globally(self, on: bool) -> TelemetryBuilder
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§
Auto Trait Implementations§
impl !Freeze for TelemetryBuilder
impl !RefUnwindSafe for TelemetryBuilder
impl !UnwindSafe for TelemetryBuilder
impl Forget for TelemetryBuilder
impl Move for TelemetryBuilder
impl Send for TelemetryBuilder
impl Sync for TelemetryBuilder
impl Unpin for TelemetryBuilder
impl UnsafeUnpin for TelemetryBuilder
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].