Skip to main content

camel_core/
config.rs

1use serde::Deserialize;
2
3/// Configuration for the Tracer EIP (Enterprise Integration Pattern).
4///
5/// This struct defines how message tracing should be performed throughout
6/// Camel routes. Use `CamelContext::set_tracer_config` to apply configuration
7/// programmatically, or configure via `Camel.toml` as shown in the module documentation.
8#[derive(Debug, Clone, Deserialize, Default)]
9pub struct TracerConfig {
10    #[serde(default)]
11    pub enabled: bool,
12
13    #[serde(default = "default_detail_level")]
14    pub detail_level: DetailLevel,
15
16    #[serde(default)]
17    pub outputs: TracerOutputs,
18}
19
20#[derive(Debug, Clone, Deserialize, Default)]
21pub struct TracerOutputs {
22    #[serde(default)]
23    pub stdout: StdoutOutput,
24
25    #[serde(default)]
26    pub file: Option<FileOutput>,
27}
28
29#[derive(Debug, Clone, Deserialize)]
30pub struct StdoutOutput {
31    #[serde(default = "default_true")]
32    pub enabled: bool,
33
34    #[serde(default = "default_format")]
35    pub format: OutputFormat,
36}
37
38impl Default for StdoutOutput {
39    fn default() -> Self {
40        Self {
41            enabled: true,
42            format: OutputFormat::Json,
43        }
44    }
45}
46
47#[derive(Debug, Clone, Deserialize)]
48pub struct FileOutput {
49    pub enabled: bool,
50    pub path: String,
51    #[serde(default = "default_format")]
52    pub format: OutputFormat,
53}
54
55/// Controls the level of detail captured in trace spans.
56///
57/// Each variant progressively adds more fields to the trace output:
58///
59/// - `Minimal`: Includes only the core fields (correlation_id, route_id, step_id,
60///   step_index, timestamp, duration_ms, status)
61/// - `Medium`: Includes Minimal fields plus headers_count, body_type, has_error,
62///   and output_body_type
63/// - `Full`: Includes all fields from Minimal and Medium plus up to 3 message headers
64#[derive(Debug, Clone, Deserialize, Default, PartialEq, Eq, PartialOrd, Ord)]
65#[serde(rename_all = "lowercase")]
66pub enum DetailLevel {
67    #[default]
68    Minimal,
69    Medium,
70    Full,
71}
72
73#[derive(Debug, Clone, Deserialize, Default)]
74#[serde(rename_all = "lowercase")]
75pub enum OutputFormat {
76    #[default]
77    Json,
78    Plain,
79}
80
81fn default_detail_level() -> DetailLevel {
82    DetailLevel::Minimal
83}
84fn default_format() -> OutputFormat {
85    OutputFormat::Json
86}
87fn default_true() -> bool {
88    true
89}