@@ -6,18 +6,18 @@ use opentelemetry::{
66 Key , KeyValue ,
77} ;
88use opentelemetry_appender_tracing:: layer:: OpenTelemetryTracingBridge ;
9+ use opentelemetry_otlp:: Protocol ;
910use opentelemetry_otlp:: { HttpExporterBuilder , WithExportConfig } ;
1011use opentelemetry_sdk:: trace:: { self as sdktrace, Config } ;
1112use opentelemetry_sdk:: {
1213 logs:: { self as sdklogs} ,
1314 Resource ,
1415} ;
16+ use std:: error:: Error ;
1517use tracing:: info;
1618use tracing_subscriber:: prelude:: * ;
1719use tracing_subscriber:: EnvFilter ;
1820
19- use std:: error:: Error ;
20-
2121#[ cfg( feature = "hyper" ) ]
2222mod hyper;
2323
@@ -39,22 +39,34 @@ fn init_logs() -> Result<sdklogs::LoggerProvider, opentelemetry::logs::LogError>
3939 opentelemetry_otlp:: new_pipeline ( )
4040 . logging ( )
4141 . with_resource ( RESOURCE . clone ( ) )
42- . with_exporter ( http_exporter ( ) . with_endpoint ( "http://localhost:4318/v1/logs" ) )
42+ . with_exporter (
43+ http_exporter ( )
44+ . with_protocol ( Protocol :: HttpBinary ) //can be changed to `Protocol::HttpJson` to export in JSON format
45+ . with_endpoint ( "http://localhost:4318/v1/logs" ) ,
46+ )
4347 . install_batch ( opentelemetry_sdk:: runtime:: Tokio )
4448}
4549
4650fn init_tracer_provider ( ) -> Result < sdktrace:: TracerProvider , TraceError > {
4751 opentelemetry_otlp:: new_pipeline ( )
4852 . tracing ( )
49- . with_exporter ( http_exporter ( ) . with_endpoint ( "http://localhost:4318/v1/traces" ) )
53+ . with_exporter (
54+ http_exporter ( )
55+ . with_protocol ( Protocol :: HttpBinary ) //can be changed to `Protocol::HttpJson` to export in JSON format
56+ . with_endpoint ( "http://localhost:4318/v1/traces" ) ,
57+ )
5058 . with_trace_config ( Config :: default ( ) . with_resource ( RESOURCE . clone ( ) ) )
5159 . install_batch ( opentelemetry_sdk:: runtime:: Tokio )
5260}
5361
5462fn init_metrics ( ) -> Result < opentelemetry_sdk:: metrics:: SdkMeterProvider , MetricsError > {
5563 opentelemetry_otlp:: new_pipeline ( )
5664 . metrics ( opentelemetry_sdk:: runtime:: Tokio )
57- . with_exporter ( http_exporter ( ) . with_endpoint ( "http://localhost:4318/v1/metrics" ) )
65+ . with_exporter (
66+ http_exporter ( )
67+ . with_protocol ( Protocol :: HttpBinary ) //can be changed to `Protocol::HttpJson` to export in JSON format
68+ . with_endpoint ( "http://localhost:4318/v1/metrics" ) ,
69+ )
5870 . with_resource ( RESOURCE . clone ( ) )
5971 . build ( )
6072}
0 commit comments