@@ -6,7 +6,7 @@ use opentelemetry::{
6
6
Key , KeyValue ,
7
7
} ;
8
8
use opentelemetry_appender_tracing:: layer:: OpenTelemetryTracingBridge ;
9
- use opentelemetry_otlp:: WithExportConfig ;
9
+ use opentelemetry_otlp:: { HttpExporterBuilder , WithExportConfig } ;
10
10
use opentelemetry_sdk:: trace:: { self as sdktrace, Config } ;
11
11
use opentelemetry_sdk:: {
12
12
logs:: { self as sdklogs} ,
@@ -18,45 +18,43 @@ use tracing_subscriber::EnvFilter;
18
18
19
19
use std:: error:: Error ;
20
20
21
+ #[ cfg( feature = "hyper" ) ]
22
+ mod hyper;
23
+
21
24
static RESOURCE : Lazy < Resource > = Lazy :: new ( || {
22
25
Resource :: new ( vec ! [ KeyValue :: new(
23
26
opentelemetry_semantic_conventions:: resource:: SERVICE_NAME ,
24
27
"basic-otlp-example" ,
25
28
) ] )
26
29
} ) ;
27
30
31
+ fn http_exporter ( ) -> HttpExporterBuilder {
32
+ let exporter = opentelemetry_otlp:: new_exporter ( ) . http ( ) ;
33
+ #[ cfg( feature = "hyper" ) ]
34
+ let exporter = exporter. with_http_client ( hyper:: HyperClient :: default ( ) ) ;
35
+ exporter
36
+ }
37
+
28
38
fn init_logs ( ) -> Result < sdklogs:: LoggerProvider , opentelemetry:: logs:: LogError > {
29
39
opentelemetry_otlp:: new_pipeline ( )
30
40
. logging ( )
31
41
. with_resource ( RESOURCE . clone ( ) )
32
- . with_exporter (
33
- opentelemetry_otlp:: new_exporter ( )
34
- . http ( )
35
- . with_endpoint ( "http://localhost:4318/v1/logs" ) ,
36
- )
42
+ . with_exporter ( http_exporter ( ) . with_endpoint ( "http://localhost:4318/v1/logs" ) )
37
43
. install_batch ( opentelemetry_sdk:: runtime:: Tokio )
38
44
}
39
45
40
46
fn init_tracer_provider ( ) -> Result < sdktrace:: TracerProvider , TraceError > {
41
47
opentelemetry_otlp:: new_pipeline ( )
42
48
. tracing ( )
43
- . with_exporter (
44
- opentelemetry_otlp:: new_exporter ( )
45
- . http ( )
46
- . with_endpoint ( "http://localhost:4318/v1/traces" ) ,
47
- )
49
+ . with_exporter ( http_exporter ( ) . with_endpoint ( "http://localhost:4318/v1/traces" ) )
48
50
. with_trace_config ( Config :: default ( ) . with_resource ( RESOURCE . clone ( ) ) )
49
51
. install_batch ( opentelemetry_sdk:: runtime:: Tokio )
50
52
}
51
53
52
54
fn init_metrics ( ) -> Result < opentelemetry_sdk:: metrics:: SdkMeterProvider , MetricsError > {
53
55
opentelemetry_otlp:: new_pipeline ( )
54
56
. metrics ( opentelemetry_sdk:: runtime:: Tokio )
55
- . with_exporter (
56
- opentelemetry_otlp:: new_exporter ( )
57
- . http ( )
58
- . with_endpoint ( "http://localhost:4318/v1/metrics" ) ,
59
- )
57
+ . with_exporter ( http_exporter ( ) . with_endpoint ( "http://localhost:4318/v1/metrics" ) )
60
58
. with_resource ( RESOURCE . clone ( ) )
61
59
. build ( )
62
60
}
0 commit comments