Skip to main content

modkit/telemetry/
config.rs

1//! OpenTelemetry tracing configuration types
2//!
3//! These types define the configuration structure for OpenTelemetry distributed tracing.
4
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// Tracing configuration for OpenTelemetry distributed tracing
9#[derive(Debug, Clone, Deserialize, Serialize, Default)]
10pub struct TracingConfig {
11    pub enabled: bool,
12    pub service_name: Option<String>,
13    pub exporter: Option<Exporter>,
14    pub sampler: Option<Sampler>,
15    pub propagation: Option<Propagation>,
16    pub resource: Option<HashMap<String, String>>,
17    pub http: Option<HttpOpts>,
18    pub logs_correlation: Option<LogsCorrelation>,
19}
20
21#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq, Copy)]
22#[serde(rename_all = "snake_case")]
23pub enum ExporterKind {
24    #[default]
25    OtlpGrpc,
26    OtlpHttp,
27}
28
29#[derive(Debug, Clone, Deserialize, Serialize)]
30pub struct Exporter {
31    pub kind: ExporterKind,
32    pub endpoint: Option<String>,
33    pub headers: Option<HashMap<String, String>>,
34    pub timeout_ms: Option<u64>,
35}
36
37#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
38#[serde(rename_all = "snake_case")]
39pub enum Sampler {
40    ParentBasedAlwaysOn {},
41    ParentBasedRatio {
42        #[serde(skip_serializing_if = "Option::is_none")]
43        ratio: Option<f64>,
44    },
45    AlwaysOn {},
46    AlwaysOff {},
47}
48
49#[derive(Debug, Clone, Deserialize, Serialize)]
50pub struct Propagation {
51    pub w3c_trace_context: Option<bool>,
52}
53
54#[derive(Debug, Clone, Deserialize, Serialize)]
55pub struct HttpOpts {
56    pub inject_request_id_header: Option<String>,
57    pub record_headers: Option<Vec<String>>,
58}
59
60#[derive(Debug, Clone, Deserialize, Serialize)]
61pub struct LogsCorrelation {
62    pub inject_trace_ids_into_logs: Option<bool>,
63}