1- //! # Stdout log exporter module.
1+ //! # OTLP log exporter module.
22//!
3- //! This module contains the definitions and common implementations for the stdout logs exporter
3+ //! This module contains the definitions and common implementations for the OTLP logs exporter
44//! that can be used with OpenTelemetry SDKs. Exporters are responsible for sending
5- //! collected logs data to different backends or systems.
5+ //! collected logs data to OTLP-compatible backends or systems.
66
77use opentelemetry_sdk:: logs:: LogExporter ;
88use serde:: { Deserialize , Deserializer } ;
@@ -30,7 +30,7 @@ impl Default for OtlpLogsBatchExporterFactory {
3030impl LogsBatchExporterFactory for OtlpLogsBatchExporterFactory {
3131
3232 /// Creates a LogExporter based on the provided configuration
33- fn create_logs_batch_exporter ( & self , config : & Value ) -> Result < impl LogExporter + ' static , Box < dyn std:: error:: Error > > {
33+ fn create_logs_batch_exporter ( & self , _config : & Value ) -> Result < impl LogExporter + ' static , Box < dyn std:: error:: Error > > {
3434 let exporter_builder = opentelemetry_otlp:: LogExporter :: builder ( ) ;
3535
3636 #[ cfg( feature = "tonic-client" ) ]
@@ -41,11 +41,13 @@ impl LogsBatchExporterFactory for OtlpLogsBatchExporterFactory {
4141 feature = "reqwest-client" ,
4242 feature = "reqwest-blocking-client"
4343 ) ) ]
44- let mut exporter_builder = exporter_builder. with_http ( ) ;
44+ let exporter_builder = exporter_builder. with_http ( ) ;
4545
46- let _config_parsed = serde_yaml:: from_value :: < OtlpConfig > ( config. clone ( ) ) ?;
46+ /*
47+ let config_parsed = serde_yaml::from_value::<OtlpConfig>(config.clone())?;
48+ */
4749
48- // TODO: Configure the exporter based on config_parsed fields. There are no methods in trhe builder to pass its parameters yet..
50+ // TODO: Configure the exporter based on config_parsed fields. There are no methods in the builder to pass its parameters yet..
4951
5052 let exporter = exporter_builder
5153 . build ( ) ?;
7779 _ => Err ( serde:: de:: Error :: custom ( format ! ( "Invalid protocol: {}" , s) ) ) ,
7880 }
7981}
82+
83+ #[ cfg( test) ]
84+ mod tests {
85+ use super :: * ;
86+ use serde_yaml:: from_str;
87+
88+ #[ tokio:: test]
89+ async fn test_default_otlp_logs_batch_exporter_factory ( ) {
90+ let factory = OtlpLogsBatchExporterFactory :: default ( ) ;
91+ assert ! ( factory. create_logs_batch_exporter( & Value :: Null ) . is_ok( ) ) ;
92+ }
93+
94+ #[ test]
95+ fn test_deserialize_otlp_config ( ) {
96+ let yaml_data = r#"
97+ protocol: "grpc"
98+ endpoint: "http://localhost:4317"
99+ "# ;
100+ let config: OtlpConfig = from_str ( yaml_data) . unwrap ( ) ;
101+ assert_eq ! ( config. protocol, Some ( opentelemetry_otlp:: Protocol :: Grpc ) ) ;
102+ assert_eq ! ( config. endpoint, Some ( "http://localhost:4317" . into( ) ) ) ;
103+ }
104+
105+ #[ test]
106+ fn test_deserialize_protocol ( ) {
107+ let yaml_grpc = r#"
108+ protocol: "grpc"
109+ "# ;
110+ let config: OtlpConfig = from_str ( yaml_grpc) . unwrap ( ) ;
111+ assert_eq ! ( config. protocol, Some ( opentelemetry_otlp:: Protocol :: Grpc ) ) ;
112+
113+ let yaml_http_binary = r#"
114+ protocol: "http/protobuf"
115+ "# ;
116+ let config: OtlpConfig = from_str ( yaml_http_binary) . unwrap ( ) ;
117+ assert_eq ! ( config. protocol, Some ( opentelemetry_otlp:: Protocol :: HttpBinary ) ) ;
118+
119+ let yaml_http_json = r#"
120+ protocol: "http/json"
121+ "# ;
122+ let config: OtlpConfig = from_str ( yaml_http_json) . unwrap ( ) ;
123+ assert_eq ! ( config. protocol, Some ( opentelemetry_otlp:: Protocol :: HttpJson ) ) ;
124+
125+ let yaml_unknown = r#"
126+ protocol: "http/unknown"
127+ "# ;
128+ let config: Result < OtlpConfig , _ > = from_str ( yaml_unknown) ;
129+ assert ! ( config. is_err( ) ) ;
130+
131+ }
132+
133+ }
0 commit comments