@@ -28,6 +28,19 @@ pub const OTEL_EXPORTER_OTLP_PROTOCOL: &str = "OTEL_EXPORTER_OTLP_PROTOCOL";
28
28
/// Compression algorithm to use, defaults to none.
29
29
pub const OTEL_EXPORTER_OTLP_COMPRESSION : & str = "OTEL_EXPORTER_OTLP_COMPRESSION" ;
30
30
31
+ /// Certificate file to validate the OTLP server connection
32
+ #[ cfg( feature = "tls" ) ]
33
+ pub const OTEL_EXPORTER_OTLP_CERTIFICATE : & str = "OTEL_EXPORTER_OTLP_CERTIFICATE" ;
34
+ /// Path to the certificate file to use for client authentication (mTLS).
35
+ #[ cfg( feature = "tls" ) ]
36
+ pub const OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE : & str = "OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE" ;
37
+ /// Path to the key file to use for client authentication (mTLS).
38
+ #[ cfg( feature = "tls" ) ]
39
+ pub const OTEL_EXPORTER_OTLP_CLIENT_KEY : & str = "OTEL_EXPORTER_OTLP_CLIENT_KEY" ;
40
+ /// Use insecure connection. Disable TLS
41
+ #[ cfg( feature = "tls" ) ]
42
+ pub const OTEL_EXPORTER_OTLP_INSECURE : & str = "OTEL_EXPORTER_OTLP_INSECURE" ;
43
+
31
44
#[ cfg( feature = "http-json" ) ]
32
45
/// Default protocol, using http-json.
33
46
pub const OTEL_EXPORTER_OTLP_PROTOCOL_DEFAULT : & str = OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_JSON ;
@@ -76,6 +89,18 @@ pub struct ExportConfig {
76
89
77
90
/// The timeout to the collector.
78
91
pub timeout : Duration ,
92
+
93
+ /// Disable TLS
94
+ pub insecure : Option < bool > ,
95
+
96
+ /// The certificate file to validate the OTLP server connection
97
+ pub certificate : Option < String > ,
98
+
99
+ /// The path to the certificate file to use for client authentication (mTLS).
100
+ pub client_certificate : Option < String > ,
101
+
102
+ /// The path to the key file to use for client authentication (mTLS).
103
+ pub client_key : Option < String > ,
79
104
}
80
105
81
106
impl Default for ExportConfig {
@@ -88,6 +113,10 @@ impl Default for ExportConfig {
88
113
// won't know if user provided a value
89
114
protocol,
90
115
timeout : Duration :: from_secs ( OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT ) ,
116
+ insecure : None ,
117
+ certificate : None ,
118
+ client_certificate : None ,
119
+ client_key : None ,
91
120
}
92
121
}
93
122
}
@@ -195,6 +224,17 @@ pub trait WithExportConfig {
195
224
fn with_timeout ( self , timeout : Duration ) -> Self ;
196
225
/// Set export config. This will override all previous configuration.
197
226
fn with_export_config ( self , export_config : ExportConfig ) -> Self ;
227
+ /// Set insecure connection. Disable TLS
228
+ fn with_insecure ( self ) -> Self ;
229
+ /// Set the certificate file to validate the OTLP server connection
230
+ /// This is only available when the `tls` feature is enabled.
231
+ fn with_certificate < T : Into < String > > ( self , certificate : T ) -> Self ;
232
+ /// Set the path to the certificate file to use for client authentication (mTLS).
233
+ /// This is only available when the `tls` feature is enabled.
234
+ fn with_client_certificate < T : Into < String > > ( self , client_certificate : T ) -> Self ;
235
+ /// Set the path to the key file to use for client authentication (mTLS).
236
+ /// This is only available when the `tls` feature is enabled.
237
+ fn with_client_key < T : Into < String > > ( self , client_key : T ) -> Self ;
198
238
}
199
239
200
240
impl < B : HasExportConfig > WithExportConfig for B {
@@ -217,6 +257,27 @@ impl<B: HasExportConfig> WithExportConfig for B {
217
257
self . export_config ( ) . endpoint = exporter_config. endpoint ;
218
258
self . export_config ( ) . protocol = exporter_config. protocol ;
219
259
self . export_config ( ) . timeout = exporter_config. timeout ;
260
+ self . export_config ( ) . insecure = Some ( true ) ;
261
+ self
262
+ }
263
+
264
+ fn with_insecure ( mut self ) -> Self {
265
+ self . export_config ( ) . insecure = Some ( true ) ;
266
+ self
267
+ }
268
+
269
+ fn with_certificate < T : Into < String > > ( mut self , certificate : T ) -> Self {
270
+ self . export_config ( ) . certificate = Some ( certificate. into ( ) ) ;
271
+ self
272
+ }
273
+
274
+ fn with_client_certificate < T : Into < String > > ( mut self , client_certificate : T ) -> Self {
275
+ self . export_config ( ) . client_certificate = Some ( client_certificate. into ( ) ) ;
276
+ self
277
+ }
278
+
279
+ fn with_client_key < T : Into < String > > ( mut self , client_key : T ) -> Self {
280
+ self . export_config ( ) . client_key = Some ( client_key. into ( ) ) ;
220
281
self
221
282
}
222
283
}
0 commit comments