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    #[serde(default)]
29    pub opentelemetry: Option<OpenTelemetryOutput>,
30}
31
32#[derive(Debug, Clone, Deserialize)]
33pub struct StdoutOutput {
34    #[serde(default = "default_true")]
35    pub enabled: bool,
36
37    #[serde(default = "default_format")]
38    pub format: OutputFormat,
39}
40
41impl Default for StdoutOutput {
42    fn default() -> Self {
43        Self {
44            enabled: true,
45            format: OutputFormat::Json,
46        }
47    }
48}
49
50#[derive(Debug, Clone, Deserialize)]
51pub struct FileOutput {
52    pub enabled: bool,
53    pub path: String,
54    #[serde(default = "default_format")]
55    pub format: OutputFormat,
56}
57
58/// Configuration for OpenTelemetry output from the tracer.
59///
60/// Note: OpenTelemetry output is not yet implemented. This type is prepared
61/// for a future release.
62#[derive(Debug, Clone, Deserialize)]
63pub struct OpenTelemetryOutput {
64    pub enabled: bool,
65    #[serde(default = "default_otel_endpoint")]
66    pub endpoint: String,
67    #[serde(default = "default_service_name")]
68    pub service_name: String,
69}
70
71/// Controls the level of detail captured in trace spans.
72///
73/// Each variant progressively adds more fields to the trace output:
74///
75/// - `Minimal`: Includes only the core fields (correlation_id, route_id, step_id,
76///   step_index, timestamp, duration_ms, status)
77/// - `Medium`: Includes Minimal fields plus headers_count, body_type, has_error,
78///   and output_body_type
79/// - `Full`: Includes all fields from Minimal and Medium plus up to 3 message headers
80#[derive(Debug, Clone, Deserialize, Default, PartialEq, Eq, PartialOrd, Ord)]
81#[serde(rename_all = "lowercase")]
82pub enum DetailLevel {
83    #[default]
84    Minimal,
85    Medium,
86    Full,
87}
88
89#[derive(Debug, Clone, Deserialize, Default)]
90#[serde(rename_all = "lowercase")]
91pub enum OutputFormat {
92    #[default]
93    Json,
94    Plain,
95}
96
97fn default_detail_level() -> DetailLevel {
98    DetailLevel::Minimal
99}
100fn default_format() -> OutputFormat {
101    OutputFormat::Json
102}
103fn default_true() -> bool {
104    true
105}
106fn default_otel_endpoint() -> String {
107    "http://localhost:4317".to_string()
108}
109fn default_service_name() -> String {
110    "rust-camel".to_string()
111}