1- /// To use hyper as the HTTP client - cargo run --features="hyper" --no-default-features
21use once_cell:: sync:: Lazy ;
32use opentelemetry:: {
43 global,
@@ -19,7 +18,7 @@ use tracing_subscriber::EnvFilter;
1918
2019static RESOURCE : Lazy < Resource > = Lazy :: new ( || {
2120 Resource :: builder ( )
22- . with_service_name ( "basic-otlp-example" )
21+ . with_service_name ( "basic-otlp-example-http " )
2322 . build ( )
2423} ) ;
2524
@@ -102,10 +101,25 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
102101 . with ( fmt_layer)
103102 . init ( ) ;
104103
104+ // At this point Logs (OTel Logs and Fmt Logs) are initialized, which will
105+ // allow internal-logs from Tracing/Metrics initializer to be captured.
106+
105107 let tracer_provider = init_traces ( ) ;
108+ // Set the global tracer provider using a clone of the tracer_provider.
109+ // Setting global tracer provider is required if other parts of the application
110+ // uses global::tracer() or global::tracer_with_version() to get a tracer.
111+ // Cloning simply creates a new reference to the same tracer provider. It is
112+ // important to hold on to the tracer_provider here, so as to invoke
113+ // shutdown on it when application ends.
106114 global:: set_tracer_provider ( tracer_provider. clone ( ) ) ;
107115
108116 let meter_provider = init_metrics ( ) ;
117+ // Set the global meter provider using a clone of the meter_provider.
118+ // Setting global meter provider is required if other parts of the application
119+ // uses global::meter() or global::meter_with_version() to get a meter.
120+ // Cloning simply creates a new reference to the same meter provider. It is
121+ // important to hold on to the meter_provider here, so as to invoke
122+ // shutdown on it when application ends.
109123 global:: set_meter_provider ( meter_provider. clone ( ) ) ;
110124
111125 let common_scope_attributes = vec ! [ KeyValue :: new( "scope-key" , "scope-value" ) ] ;
@@ -147,8 +161,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
147161 info ! ( target: "my-target" , "hello from {}. My price is {}" , "apple" , 1.99 ) ;
148162
149163 tracer_provider. shutdown ( ) ?;
150- logger_provider. shutdown ( ) ?;
151164 meter_provider. shutdown ( ) ?;
165+ logger_provider. shutdown ( ) ?;
152166
153167 Ok ( ( ) )
154168}
0 commit comments