Skip to main content

camel_core/
lib.rs

1//! # Camel Core
2//!
3//! This crate provides the core functionality for the Apache Camel implementation in Rust.
4//!
5//! ## Tracer EIP
6//!
7//! The Tracer Enterprise Integration Pattern (EIP) provides automatic message flow tracing
8//! throughout your Camel routes. It captures detailed information about each step as messages
9//! flow through the integration routes, helping with debugging, monitoring, and observability.
10//!
11//! ### Configuration
12//!
13//! You can configure the tracer in your `Camel.toml` file:
14//!
15//! ```toml
16//! [observability.tracer]
17//! enabled = true
18//! detail_level = "minimal"  # minimal | medium | full
19//!
20//! [observability.tracer.outputs.stdout]
21//! enabled = true
22//! format = "json"
23//! ```
24//!
25//! Or enable it programmatically:
26//!
27//! ```ignore
28//! use camel_core::CamelContext;
29//! let mut ctx = CamelContext::builder().build().await.unwrap();
30//! ctx.set_tracing(true).await;
31//! ```
32//!
33//! ### Span Fields
34//!
35//! Each trace span includes the following fields:
36//!
37//! - `correlation_id`: Unique identifier that links all spans in a single message flow
38//! - `route_id`: Identifier for the route being traced
39//! - `step_id`: Unique identifier for this specific step in the route
40//! - `step_index`: Sequential index of this step within the route
41//! - `timestamp`: When the step was executed (Unix timestamp)
42//! - `duration_ms`: How long the step took to execute in milliseconds
43//! - `status`: The status of the step execution (e.g., "success", "error")
44//!
45//! ### Detail Levels
46//!
47//! The tracer supports three levels of detail:
48//!
49//! - **Minimal**: Includes only the base fields listed above
50//! - **Medium**: Includes the base fields plus:
51//!   - `headers_count`: Number of message headers
52//!   - `body_type`: Type of the message body
53//!   - `has_error`: Whether the message contains an error
54//!   - `output_body_type`: Type of the output body after processing
55//! - **Full**: Includes all fields from Minimal and Medium plus:
56//!   - Up to 3 message headers (`header_0`, `header_1`, `header_2`)
57//!
58//! //! Configuration types for the Tracer EIP live in `camel-core` rather than `camel-config`
59//! //! to avoid a circular dependency — `camel-config` depends on `camel-core`.
60//!
61pub mod context;
62pub mod health_registry;
63pub(crate) mod hot_reload;
64pub mod lifecycle;
65pub(crate) mod shared;
66pub mod step;
67pub mod template;
68
69#[cfg(feature = "internal-adapters")]
70pub mod route {
71    pub use crate::lifecycle::adapters::route_compiler::{
72        compose_pipeline, compose_pipeline_with_contracts, compose_traced_pipeline,
73    };
74    pub use crate::lifecycle::adapters::route_types::Route;
75    pub use crate::lifecycle::application::route_definition::*;
76    pub use crate::lifecycle::domain::route::RouteSpec;
77}
78
79#[cfg(feature = "internal-adapters")]
80pub mod route_controller {
81    pub use crate::lifecycle::adapters::route_controller::*;
82}
83
84pub mod supervising_route_controller {
85    pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
86}
87
88pub mod reload_watcher {
89    pub use crate::hot_reload::adapters::reload_watcher::*;
90    pub use crate::hot_reload::application::FunctionReloadContext;
91    pub use crate::hot_reload::application::execute_reload_actions;
92    pub use crate::hot_reload::domain::ReloadAction;
93}
94
95pub use crate::hot_reload::adapters::ReloadWatcher;
96pub use crate::hot_reload::application::FunctionReloadContext;
97pub use crate::hot_reload::application::execute_reload_actions;
98pub use crate::hot_reload::domain::ReloadAction;
99pub use crate::lifecycle::adapters::controller_actor::RouteControllerHandle;
100pub use crate::lifecycle::adapters::controller_actor::spawn_controller_actor;
101pub use crate::lifecycle::adapters::controller_actor::spawn_supervision_task;
102#[cfg(feature = "internal-adapters")]
103pub use crate::lifecycle::adapters::exchange_uow::ExchangeUoWLayer;
104#[cfg(feature = "internal-adapters")]
105pub use crate::lifecycle::adapters::redb_journal::{
106    JournalDurability, JournalEntry, JournalInspectFilter, RedbJournalOptions,
107    RedbRuntimeEventJournal,
108};
109#[cfg(feature = "internal-adapters")]
110pub use crate::lifecycle::adapters::route_controller::DefaultRouteController;
111#[cfg(feature = "internal-adapters")]
112pub use crate::lifecycle::adapters::route_types::Route;
113#[cfg(feature = "internal-adapters")]
114pub use crate::lifecycle::adapters::{
115    InMemoryCommandDedup, InMemoryEventPublisher, InMemoryProjectionStore, InMemoryRouteRepository,
116    InMemoryRuntimeStore, RuntimeExecutionAdapter,
117};
118pub use crate::lifecycle::application::runtime_bus::RuntimeBus;
119pub use crate::lifecycle::application::{BuilderStep, RouteDefinition};
120pub use crate::lifecycle::domain::{
121    LanguageRegistryError, RouteLifecycleCommand, RouteRuntimeAggregate, RouteRuntimeState,
122    RuntimeEvent,
123};
124pub use crate::lifecycle::ports::{
125    CommandDedupPort, EventPublisherPort, InFlightCountResult, ProjectionStorePort,
126    RouteRepositoryPort, RouteStatusProjection, RuntimeEventJournalPort, RuntimeExecutionPort,
127    RuntimeUnitOfWorkPort,
128};
129pub use crate::shared::components::domain::Registry;
130pub use crate::shared::observability::adapters::TracingProcessor;
131pub use crate::shared::observability::domain::{
132    DetailLevel, FileOutput, OutputFormat, StdoutOutput, TracerConfig, TracerOutputs,
133};
134pub use context::CamelContext;
135pub use template::TemplateRegistry;
136
137// Re-export route controller types from camel-api (they live there to avoid cyclic dependencies).
138pub use camel_api::CamelError;
139pub use camel_api::{RouteAction, RouteController, RouteStatus};
140
141impl From<lifecycle::domain::DomainError> for CamelError {
142    fn from(e: lifecycle::domain::DomainError) -> Self {
143        CamelError::RouteError(e.to_string())
144    }
145}
146
147impl From<lifecycle::domain::LanguageRegistryError> for CamelError {
148    fn from(e: lifecycle::domain::LanguageRegistryError) -> Self {
149        CamelError::Config(e.to_string())
150    }
151}