@@ -6,18 +6,18 @@ use opentelemetry::{
6
6
Key , KeyValue ,
7
7
} ;
8
8
use opentelemetry_appender_tracing:: layer:: OpenTelemetryTracingBridge ;
9
+ use opentelemetry_otlp:: Protocol ;
9
10
use opentelemetry_otlp:: { HttpExporterBuilder , WithExportConfig } ;
10
11
use opentelemetry_sdk:: trace:: { self as sdktrace, Config } ;
11
12
use opentelemetry_sdk:: {
12
13
logs:: { self as sdklogs} ,
13
14
Resource ,
14
15
} ;
16
+ use std:: error:: Error ;
15
17
use tracing:: info;
16
18
use tracing_subscriber:: prelude:: * ;
17
19
use tracing_subscriber:: EnvFilter ;
18
20
19
- use std:: error:: Error ;
20
-
21
21
#[ cfg( feature = "hyper" ) ]
22
22
mod hyper;
23
23
@@ -39,22 +39,34 @@ fn init_logs() -> Result<sdklogs::LoggerProvider, opentelemetry::logs::LogError>
39
39
opentelemetry_otlp:: new_pipeline ( )
40
40
. logging ( )
41
41
. 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
+ )
43
47
. install_batch ( opentelemetry_sdk:: runtime:: Tokio )
44
48
}
45
49
46
50
fn init_tracer_provider ( ) -> Result < sdktrace:: TracerProvider , TraceError > {
47
51
opentelemetry_otlp:: new_pipeline ( )
48
52
. 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
+ )
50
58
. with_trace_config ( Config :: default ( ) . with_resource ( RESOURCE . clone ( ) ) )
51
59
. install_batch ( opentelemetry_sdk:: runtime:: Tokio )
52
60
}
53
61
54
62
fn init_metrics ( ) -> Result < opentelemetry_sdk:: metrics:: SdkMeterProvider , MetricsError > {
55
63
opentelemetry_otlp:: new_pipeline ( )
56
64
. 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
+ )
58
70
. with_resource ( RESOURCE . clone ( ) )
59
71
. build ( )
60
72
}
0 commit comments