Skip to main content

rustapi_core/app/
production.rs

1/// Configuration for RustAPI's built-in production baseline preset.
2///
3/// This preset bundles together the most common foundation pieces for a
4/// production HTTP service:
5/// - request IDs on every response
6/// - structured tracing spans with service metadata
7/// - standard `/health`, `/ready`, and `/live` probes
8#[derive(Debug, Clone)]
9pub struct ProductionDefaultsConfig {
10    pub(super) service_name: String,
11    pub(super) version: Option<String>,
12    pub(super) tracing_level: tracing::Level,
13    pub(super) health_endpoint_config: Option<crate::health::HealthEndpointConfig>,
14    pub(super) enable_request_id: bool,
15    pub(super) enable_tracing: bool,
16    pub(super) enable_health_endpoints: bool,
17}
18
19impl ProductionDefaultsConfig {
20    /// Create a new production baseline configuration.
21    pub fn new(service_name: impl Into<String>) -> Self {
22        Self {
23            service_name: service_name.into(),
24            version: None,
25            tracing_level: tracing::Level::INFO,
26            health_endpoint_config: None,
27            enable_request_id: true,
28            enable_tracing: true,
29            enable_health_endpoints: true,
30        }
31    }
32
33    /// Annotate tracing spans and default health payloads with an application version.
34    pub fn version(mut self, version: impl Into<String>) -> Self {
35        self.version = Some(version.into());
36        self
37    }
38
39    /// Set the tracing log level used by the preset tracing layer.
40    pub fn tracing_level(mut self, level: tracing::Level) -> Self {
41        self.tracing_level = level;
42        self
43    }
44
45    /// Override the default health endpoint paths.
46    pub fn health_endpoint_config(mut self, config: crate::health::HealthEndpointConfig) -> Self {
47        self.health_endpoint_config = Some(config);
48        self
49    }
50
51    /// Enable or disable request ID propagation.
52    pub fn request_id(mut self, enabled: bool) -> Self {
53        self.enable_request_id = enabled;
54        self
55    }
56
57    /// Enable or disable structured tracing middleware.
58    pub fn tracing(mut self, enabled: bool) -> Self {
59        self.enable_tracing = enabled;
60        self
61    }
62
63    /// Enable or disable built-in health endpoints.
64    pub fn health_endpoints(mut self, enabled: bool) -> Self {
65        self.enable_health_endpoints = enabled;
66        self
67    }
68}