tracing_elastic_apm/
config.rs

1//! Layer configuration.
2
3use crate::model::{Cloud, Framework, Language, Process, Runtime, ServiceNode, System, User};
4
5/// Name for the trace id field, if one needs to be supplied manually.
6pub const TRACE_ID_FIELD_NAME: &str = "trace_id";
7
8pub struct Service {
9    pub(crate) version: Option<String>,
10    pub(crate) environment: Option<String>,
11    pub(crate) language: Option<Language>,
12    pub(crate) runtime: Option<Runtime>,
13    pub(crate) framework: Option<Framework>,
14    pub(crate) node: Option<ServiceNode>,
15}
16
17impl Service {
18    pub fn new(
19        version: Option<String>,
20        environment: Option<String>,
21        language: Option<Language>,
22        runtime: Option<Runtime>,
23        framework: Option<Framework>,
24        node: Option<ServiceNode>,
25    ) -> Self {
26        Service {
27            version,
28            environment,
29            language,
30            runtime,
31            framework,
32            node,
33        }
34    }
35}
36
37pub struct ApiKey {
38    pub(crate) id: String,
39    pub(crate) key: String,
40}
41
42impl ApiKey {
43    pub fn new(id: String, key: String) -> Self {
44        ApiKey { id, key }
45    }
46}
47
48/// APM authorization method.
49pub enum Authorization {
50    SecretToken(String),
51    ApiKey(ApiKey),
52}
53
54#[derive(Default)]
55pub struct Config {
56    pub(crate) apm_address: String,
57    pub(crate) authorization: Option<Authorization>,
58    pub(crate) service: Option<Service>,
59    pub(crate) process: Option<Process>,
60    pub(crate) system: Option<System>,
61    pub(crate) user: Option<User>,
62    pub(crate) cloud: Option<Cloud>,
63    pub(crate) allow_invalid_certs: bool,
64    pub(crate) root_cert_path: Option<String>,
65}
66
67impl Config {
68    pub fn new(apm_address: String) -> Self {
69        Config {
70            apm_address,
71            ..Default::default()
72        }
73    }
74
75    pub fn allow_invalid_certificates(mut self, verify: bool) -> Self {
76        self.allow_invalid_certs = verify;
77        self
78    }
79
80    pub fn with_root_cert_path(mut self, cert_path: String) -> Self {
81        self.root_cert_path = Some(cert_path);
82        self
83    }
84
85    pub fn with_authorization(mut self, authorization: Authorization) -> Self {
86        self.authorization = Some(authorization);
87        self
88    }
89
90    pub fn with_service(mut self, service: Service) -> Self {
91        self.service = Some(service);
92        self
93    }
94
95    pub fn with_process(mut self, process: Process) -> Self {
96        self.process = Some(process);
97        self
98    }
99
100    pub fn with_system(mut self, system: System) -> Self {
101        self.system = Some(system);
102        self
103    }
104
105    pub fn with_user(mut self, user: User) -> Self {
106        self.user = Some(user);
107        self
108    }
109
110    pub fn with_cloud(mut self, cloud: Cloud) -> Self {
111        self.cloud = Some(cloud);
112        self
113    }
114}