Skip to main content

camel_core/shared/observability/domain/
config.rs

1use std::fmt;
2use std::sync::Arc;
3
4use serde::Deserialize;
5
6use camel_api::metrics::MetricsCollector;
7
8/// Configuration for the Tracer EIP (Enterprise Integration Pattern).
9///
10/// This struct defines how message tracing should be performed throughout
11/// Camel routes. Use `CamelContext::set_tracer_config` to apply configuration
12/// programmatically, or configure via `Camel.toml` as shown in the module documentation.
13#[derive(Clone, Deserialize, Default)]
14pub struct TracerConfig {
15    #[serde(default)]
16    pub enabled: bool,
17
18    #[serde(default = "default_detail_level")]
19    pub detail_level: DetailLevel,
20
21    #[serde(default)]
22    pub outputs: TracerOutputs,
23
24    /// Metrics collector for recording route-level metrics.
25    /// Not serializable - injected at runtime.
26    #[serde(skip)]
27    pub metrics_collector: Option<Arc<dyn MetricsCollector>>,
28}
29
30impl fmt::Debug for TracerConfig {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        f.debug_struct("TracerConfig")
33            .field("enabled", &self.enabled)
34            .field("detail_level", &self.detail_level)
35            .field("outputs", &self.outputs)
36            .field(
37                "metrics_collector",
38                &self.metrics_collector.as_ref().map(|_| "MetricsCollector"),
39            )
40            .finish()
41    }
42}
43
44#[derive(Debug, Clone, Deserialize, Default)]
45pub struct TracerOutputs {
46    #[serde(default)]
47    pub stdout: StdoutOutput,
48
49    #[serde(default)]
50    pub file: Option<FileOutput>,
51}
52
53#[derive(Debug, Clone, Deserialize)]
54pub struct StdoutOutput {
55    #[serde(default = "default_true")]
56    pub enabled: bool,
57
58    #[serde(default = "default_format")]
59    pub format: OutputFormat,
60}
61
62impl Default for StdoutOutput {
63    fn default() -> Self {
64        Self {
65            enabled: true,
66            format: OutputFormat::Json,
67        }
68    }
69}
70
71#[derive(Debug, Clone, Deserialize)]
72pub struct FileOutput {
73    pub enabled: bool,
74    pub path: String,
75    #[serde(default = "default_format")]
76    pub format: OutputFormat,
77}
78
79/// Controls the level of detail captured in trace spans.
80///
81/// Each variant progressively adds more fields to the trace output:
82///
83/// - `Minimal`: Includes only the core fields (correlation_id, route_id, step_id,
84///   step_index, timestamp, duration_ms, status)
85/// - `Medium`: Includes Minimal fields plus headers_count, body_type, has_error,
86///   and output_body_type
87/// - `Full`: Includes all fields from Minimal and Medium plus up to 3 message headers
88#[derive(Debug, Clone, Deserialize, Default, PartialEq, Eq, PartialOrd, Ord)]
89#[serde(rename_all = "lowercase")]
90pub enum DetailLevel {
91    #[default]
92    Minimal,
93    Medium,
94    Full,
95}
96
97#[derive(Debug, Clone, Deserialize, Default)]
98#[serde(rename_all = "lowercase")]
99pub enum OutputFormat {
100    #[default]
101    Json,
102    Plain,
103}
104
105fn default_detail_level() -> DetailLevel {
106    DetailLevel::Minimal
107}
108fn default_format() -> OutputFormat {
109    OutputFormat::Json
110}
111fn default_true() -> bool {
112    true
113}