Skip to main content

fraiseql_server/config/
tracing.rs

1//! Tracing and logging configuration.
2
3use serde::Deserialize;
4
5/// Distributed-tracing and structured-logging configuration.
6#[derive(Debug, Clone, Deserialize)]
7pub struct TracingConfig {
8    /// Whether tracing/logging is active.  Default: `true`.
9    #[serde(default = "default_enabled")]
10    pub enabled: bool,
11
12    /// Log level filter
13    #[serde(default = "default_level")]
14    pub level: String,
15
16    /// Log format: json, pretty
17    #[serde(default = "default_format")]
18    pub format: String,
19
20    /// Service name for distributed tracing
21    #[serde(default = "default_service_name")]
22    pub service_name: String,
23
24    /// OTLP exporter endpoint.
25    ///
26    /// When set (e.g. `"http://otel-collector:4317"`), the server initializes an
27    /// `OpenTelemetry` OTLP exporter and pipes `tracing` spans to it.
28    /// When `None`, the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable is
29    /// checked as a fallback. If neither is set, no OTLP export occurs and there
30    /// is zero overhead (no gRPC connection attempt).
31    #[serde(default)]
32    pub otlp_endpoint: Option<String>,
33
34    /// OTLP exporter timeout in seconds.
35    ///
36    /// Controls how long the OTLP HTTP exporter waits for a response from the
37    /// collector before timing out. Defaults to 10 seconds.
38    /// Override via `[tracing] otlp_export_timeout_secs = 30` in `fraiseql.toml`.
39    #[serde(default = "default_otlp_timeout_secs")]
40    pub otlp_export_timeout_secs: u64,
41}
42
43impl Default for TracingConfig {
44    fn default() -> Self {
45        Self {
46            enabled:                  default_enabled(),
47            level:                    default_level(),
48            format:                   default_format(),
49            service_name:             default_service_name(),
50            otlp_endpoint:            None,
51            otlp_export_timeout_secs: default_otlp_timeout_secs(),
52        }
53    }
54}
55
56const fn default_enabled() -> bool {
57    true
58}
59fn default_level() -> String {
60    "info".to_string()
61}
62fn default_format() -> String {
63    "json".to_string()
64}
65fn default_service_name() -> String {
66    "fraiseql".to_string()
67}
68const fn default_otlp_timeout_secs() -> u64 {
69    10
70}