a2a_protocol_server/otel/telemetry/builder/options.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F. <[email protected]> (https://github.com/tomtom215)
3
4//! The builder's options for what `Telemetry` adds beyond the three signals:
5//! the console format, the Prometheus listener, process and runtime metrics.
6
7use super::TelemetryBuilder;
8
9impl TelemetryBuilder {
10 /// Under `OTEL_METRICS_EXPORTER=prometheus`, binds no listener of its
11 /// own: the application serves the text of
12 /// [`Telemetry::prometheus`](crate::otel::Telemetry::prometheus) on its own
13 /// port, behind its own authentication and connection limits (audit
14 /// C-16). `OTEL_EXPORTER_PROMETHEUS_HOST` and `_PORT` are then not read.
15 #[cfg(feature = "otel-prometheus")]
16 #[must_use]
17 pub const fn without_prometheus_listener(mut self) -> Self {
18 self.prometheus_listener = false;
19 self
20 }
21
22 /// Reports no process or Tokio runtime metrics. By default, when metrics
23 /// are exported, `process.cpu.time`, `process.memory.usage`,
24 /// `process.memory.virtual`, `process.thread.count` and
25 /// `process.unix.file_descriptor.count` are reported on Linux, and
26 /// `tokio.runtime.worker.count`, `tokio.runtime.task.count` and
27 /// `tokio.runtime.global_queue.depth` for the runtime `build` runs in
28 /// (audit C-13).
29 #[must_use]
30 pub const fn without_process_metrics(mut self) -> Self {
31 self.process_metrics = false;
32 self
33 }
34
35 /// Reports the Tokio runtime metrics of the runtime `handle` drives,
36 /// instead of the one `build` runs in (if any). For an application that
37 /// builds `Telemetry` before entering its runtime.
38 #[must_use]
39 pub fn with_tokio_runtime(mut self, handle: tokio::runtime::Handle) -> Self {
40 self.runtime = Some(handle);
41 self
42 }
43
44 /// The format `install_subscriber` prints in: text (the default) or one
45 /// JSON object per line with `trace_id`, `span_id` and `trace_flags`
46 /// inside a span (audit C-06). Wins over `A2A_LOG_FORMAT` (`json` or
47 /// `text`), which applies when this is not called.
48 #[must_use]
49 pub const fn with_console_format(mut self, format: super::super::ConsoleFormat) -> Self {
50 self.console_format = Some(format);
51 self
52 }
53}