@@ -28,6 +28,19 @@ pub const OTEL_EXPORTER_OTLP_PROTOCOL: &str = "OTEL_EXPORTER_OTLP_PROTOCOL";
2828/// Compression algorithm to use, defaults to none.
2929pub const OTEL_EXPORTER_OTLP_COMPRESSION : & str = "OTEL_EXPORTER_OTLP_COMPRESSION" ;
3030
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+
3144#[ cfg( feature = "http-json" ) ]
3245/// Default protocol, using http-json.
3346pub const OTEL_EXPORTER_OTLP_PROTOCOL_DEFAULT : & str = OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_JSON ;
@@ -76,6 +89,18 @@ pub struct ExportConfig {
7689
7790 /// The timeout to the collector.
7891 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 > ,
79104}
80105
81106impl Default for ExportConfig {
@@ -88,6 +113,10 @@ impl Default for ExportConfig {
88113 // won't know if user provided a value
89114 protocol,
90115 timeout : Duration :: from_secs ( OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT ) ,
116+ insecure : None ,
117+ certificate : None ,
118+ client_certificate : None ,
119+ client_key : None ,
91120 }
92121 }
93122}
@@ -195,6 +224,17 @@ pub trait WithExportConfig {
195224 fn with_timeout ( self , timeout : Duration ) -> Self ;
196225 /// Set export config. This will override all previous configuration.
197226 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 ;
198238}
199239
200240impl < B : HasExportConfig > WithExportConfig for B {
@@ -217,6 +257,27 @@ impl<B: HasExportConfig> WithExportConfig for B {
217257 self . export_config ( ) . endpoint = exporter_config. endpoint ;
218258 self . export_config ( ) . protocol = exporter_config. protocol ;
219259 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 ( ) ) ;
220281 self
221282 }
222283}
0 commit comments