Skip to main content

ObservabilityConfig

Struct ObservabilityConfig 

Source
pub struct ObservabilityConfig {
    pub enabled: bool,
    pub service_name: Option<String>,
    pub service_version: Option<String>,
    pub environment: Option<String>,
    pub resource_attributes: BTreeMap<String, String>,
    pub logs: LogsConfig,
    pub traces: TracesConfig,
    pub metrics: MetricsConfig,
    pub otlp: OtlpConfig,
}
Expand description

Logs, traces and metrics — what the server says about itself, and where it says it.

Everything here is off-by-default except the logs, which every process has always written to the terminal. Turning enabled on does not by itself send anything anywhere: it arms the section, and an [observability.otlp] endpoint is what makes traces and metrics leave the process. Without one the spans are still built and still carried through the logs — so a deployment gets request ids and structured errors for free, and an OTLP collector only when it has somewhere to put the data.

§Why OTLP and nothing else

OTLP is the wire format every backend now speaks — Jaeger, Tempo, Honeycomb, Datadog, New Relic, the OpenTelemetry Collector — so one exporter reaches all of them, and a deployment that wants something exotic points this at a Collector and translates there rather than here. The transport is HTTP (:4318), not gRPC: it goes through the reqwest client this binary already links, where gRPC would compile a second RPC stack for the same bytes.

§Environment

The standard OTEL_* variables are read when the corresponding key is unset — OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_SERVICE_NAME, OTEL_TRACES_SAMPLER_ARG — because that is how a sidecar-injected collector configures the pods around it, and an app should not have to be rebuilt to be scraped.

Fields§

§enabled: bool

Arm the section. Off means: log to the terminal as always, build no spans, export nothing.

§service_name: Option<String>

What this service calls itself in a trace. Unset falls back to OTEL_SERVICE_NAME, then to the app’s name, then to apiplant.

§service_version: Option<String>

The build being traced. Unset falls back to the apiplant version, which is right until an app starts shipping a version of its own.

§environment: Option<String>

production, staging, … Exported as deployment.environment.name, which is the attribute every backend groups by first.

§resource_attributes: BTreeMap<String, String>

Extra resource attributes attached to every span and metric — region, tenant, k8s.pod.name. Values may reference the environment like any other string here.

§logs: LogsConfig§traces: TracesConfig§metrics: MetricsConfig§otlp: OtlpConfig

Implementations§

Source§

impl ObservabilityConfig

Source

pub fn endpoint(&self) -> Option<String>

The endpoint to export to, config first and then the environment.

None means nothing is exported — which is a supported way to run: spans still carry the logs, they simply stay in the process.

Source

pub fn service_name(&self, app_name: &str) -> String

The name this service reports itself under.

Source

pub fn export_headers(&self) -> BTreeMap<String, String>

Every header sent with an export, the config’s merged over anything OTEL_EXPORTER_OTLP_HEADERS supplied — the file is the more specific statement, so it wins a collision.

Source

pub fn is_active(&self) -> bool

Whether anything at all is being collected.

Trait Implementations§

Source§

impl Clone for ObservabilityConfig

Source§

fn clone(&self) -> ObservabilityConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ObservabilityConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ObservabilityConfig

Source§

fn default() -> ObservabilityConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ObservabilityConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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
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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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