datadog_logs/
config.rs

1use serde::{Deserialize, Serialize};
2use std::default::Default;
3
4/// Configuration for DataDogLogger
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct DataDogConfig {
7    /// Tags to add to each log.
8    pub tags: Option<String>,
9    /// DataDog API key.
10    /// It is required to specify API key. Not doing it is considered an error.
11    pub apikey: String,
12    /// Service name to add to each log.
13    pub service: Option<String>,
14    /// Hostname to add to each log.
15    pub hostname: Option<String>,
16    /// Source to add to each log.
17    /// Default value is `rust`.
18    #[serde(default)]
19    pub source: String,
20    /// HTTP client specific configuration.
21    /// It only needs to be specified for HTTP logging in case of non-default settings.
22    /// Otherwise default is assumed.
23    #[serde(default)]
24    pub http_config: DataDogHttpConfig,
25    /// TCP client specific configuration
26    /// It only needs to be specified for TCP logging in case of non-default settings.
27    /// Otherwise default is assumed.
28    ///
29    /// Even though the crate does not support TCP client now, config is here to be an extensibility point.
30    #[serde(default)]
31    pub tcp_config: DataDogTcpConfig,
32    /// Capacity of channel connecting logger thread with other threads.
33    /// If not set explicitly, it defaults to 10 000 messages.
34    /// If explicitly set to `None`, channel will be unbounded.
35    #[serde(default)]
36    pub messages_channel_capacity: Option<usize>,
37    /// Enables or disables self logging. Disabled by default.
38    #[serde(default)]
39    pub enable_self_log: bool,
40}
41
42impl Default for DataDogConfig {
43    fn default() -> Self {
44        DataDogConfig {
45            tags: None,
46            apikey: "".into(),
47            service: None,
48            hostname: None,
49            http_config: Default::default(),
50            tcp_config: Default::default(),
51            source: "rust".into(),
52            messages_channel_capacity: Some(10_000),
53            enable_self_log: false,
54        }
55    }
56}
57
58/// HTTP specific Datadog connectivity configuration
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct DataDogHttpConfig {
61    /// Url of DataDog service along with scheme and path.
62    /// To keeps library as flexible as possible no check is performed on passed URL.
63    /// It is important that you specify correct geography and subdomain.
64    /// To log via HTTPS simply specify HTTPS scheme in the URL.
65    /// If you prefer unencrypted connection, specify HTTP scheme.
66    ///
67    /// Default value is `https://http-intake.logs.datadoghq.com/v1/input`.
68    #[serde(default)]
69    pub url: String,
70}
71
72impl Default for DataDogHttpConfig {
73    fn default() -> Self {
74        DataDogHttpConfig {
75            url: "https://http-intake.logs.datadoghq.com/v1/input".into(),
76        }
77    }
78}
79
80/// TCP specific Datadog connectivity configuration
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct DataDogTcpConfig {
83    /// If set to true will force TLS connction to DataDog for TCP. True by default.
84    #[serde(default)]
85    pub use_tls: bool,
86    /// Datadog service domain without scheme or path parts of URL e.g. `intake.logs.datadoghq.com`.
87    ///
88    /// Default value is `intake.logs.datadoghq.com`. However it might need to be changed for differerent geographies e.g. Europe.
89    #[serde(default)]
90    pub domain: String,
91    /// Port for unencrypted connections to Datadog. By default it is `10514` as specified in Datadog documentation.
92    /// It is possible to change it in case Datadog changes it in the future.
93    #[serde(default)]
94    pub non_tls_port: usize,
95    /// Port for encrypted connections. It defaults to 443.
96    #[serde(default)]
97    pub tls_port: usize,
98}
99
100impl Default for DataDogTcpConfig {
101    /// Default configuration is US default config.
102    /// EU config needs to be input manually.
103    fn default() -> Self {
104        DataDogTcpConfig {
105            use_tls: true,
106            domain: "intake.logs.datadoghq.com".into(),
107            non_tls_port: 10514,
108            tls_port: 443,
109        }
110    }
111}