11use crate :: { constants:: OTEL_SERVICE_NAMESPACE , trace:: OtelConfig } ;
22use opentelemetry:: KeyValue ;
33use opentelemetry_otlp:: WithExportConfig ;
4- use opentelemetry_sdk:: { runtime, Resource } ;
5- use opentelemetry_semantic_conventions:: {
6- resource:: { SERVICE_NAME , SERVICE_NAMESPACE , SERVICE_VERSION } ,
7- SCHEMA_URL ,
8- } ;
4+ use opentelemetry_sdk:: Resource ;
5+ use opentelemetry_semantic_conventions:: resource:: { SERVICE_NAME , SERVICE_NAMESPACE , SERVICE_VERSION } ;
96
107#[ cfg( feature = "otel-trace" ) ]
11- use opentelemetry_sdk:: trace:: { BatchConfigBuilder , Builder as SdkBuilder , RandomIdGenerator , Sampler , Tracer } ;
8+ use opentelemetry_sdk:: trace:: { BatchConfigBuilder , RandomIdGenerator , Sampler , Tracer , TracerProviderBuilder as SdkBuilder } ;
129
1310#[ cfg( feature = "otel-trace" ) ]
1411use opentelemetry:: trace:: TracerProvider ;
@@ -28,16 +25,25 @@ where
2825 T : Into < String > + Clone ,
2926 opentelemetry:: Value : From < T > ,
3027{
31- Resource :: from_schema_url (
32- [
28+ Resource :: builder ( )
29+ . with_attributes ( vec ! [
3330 KeyValue :: new( SERVICE_NAMESPACE , OTEL_SERVICE_NAMESPACE ) ,
3431 KeyValue :: new( SERVICE_NAME , env!( "CARGO_PKG_NAME" ) ) ,
3532 KeyValue :: new( SERVICE_VERSION , env!( "CARGO_PKG_VERSION" ) ) ,
3633 #[ cfg( feature = "otel-instance-id" ) ]
3734 KeyValue :: new( SERVICE_INSTANCE_ID , _otel_config. service_instance_id. clone( ) . into( ) ) ,
38- ] ,
39- SCHEMA_URL ,
40- )
35+ ] )
36+ . build ( )
37+ // Resource::from_schema_url(
38+ // [
39+ // KeyValue::new(SERVICE_NAMESPACE, OTEL_SERVICE_NAMESPACE),
40+ // KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")),
41+ // KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION")),
42+ // #[cfg(feature = "otel-instance-id")]
43+ // KeyValue::new(SERVICE_INSTANCE_ID, _otel_config.service_instance_id.clone().into()),
44+ // ],
45+ // SCHEMA_URL,
46+ // )
4147}
4248
4349#[ cfg( feature = "otel-metrics" ) ]
@@ -58,30 +64,32 @@ where
5864 . build ( )
5965 . unwrap ( ) ;
6066
61- let reader = PeriodicReader :: builder ( exporter, runtime :: Tokio )
67+ let reader = PeriodicReader :: builder ( exporter)
6268 . with_interval ( std:: time:: Duration :: from_secs ( 30 ) )
6369 . build ( ) ;
6470
6571 // For debugging in development
6672 let stdout_exporter = opentelemetry_stdout:: MetricExporter :: default ( ) ;
67- let stdout_reader = PeriodicReader :: builder ( stdout_exporter, runtime :: Tokio ) . build ( ) ;
73+ let stdout_reader = PeriodicReader :: builder ( stdout_exporter) . build ( ) ;
6874
6975 // define view
7076 let view = |instrument : & Instrument | -> Option < Stream > {
7177 // add prefix to metrics names
72- let stream = Stream :: new ( )
73- . name ( format ! ( "{}_{}" , OTEL_SERVICE_NAMESPACE , instrument. name) ) // add prefix to metrics names
74- . description ( instrument. description . clone ( ) )
75- . unit ( instrument. unit . clone ( ) ) ;
78+ let instrument_name = instrument. name ( ) . to_string ( ) ;
79+ let instrument_unit = instrument. unit ( ) . to_string ( ) ;
80+
81+ let mut stream_builder = Stream :: builder ( )
82+ . with_name ( format ! ( "{}_{}" , OTEL_SERVICE_NAMESPACE , instrument_name) ) // add prefix to metrics names
83+ // .with_description(instrument.description().clone())
84+ . with_unit ( instrument_unit) ;
7685
77- if instrument . name . contains ( "latency_" ) {
78- Some ( stream . aggregation ( Aggregation :: ExplicitBucketHistogram {
86+ if instrument_name . contains ( "latency_" ) {
87+ stream_builder = stream_builder . with_aggregation ( Aggregation :: ExplicitBucketHistogram {
7988 boundaries : vec ! [ 25.0 , 50.0 , 100.0 , 200.0 , 400.0 , 800.0 , 1600.0 , 3200.0 ] ,
8089 record_min_max : true ,
81- } ) )
82- } else {
83- Some ( stream)
90+ } ) ;
8491 }
92+ stream_builder. build ( ) . ok ( )
8593 } ;
8694
8795 let meter_provider = SdkMeterProvider :: builder ( )
@@ -110,7 +118,7 @@ where
110118 . with_endpoint ( otlp_endpoint)
111119 . build ( )
112120 . unwrap ( ) ;
113- let batch_processor = opentelemetry_sdk:: trace:: BatchSpanProcessor :: builder ( exporter, runtime :: Tokio )
121+ let batch_processor = opentelemetry_sdk:: trace:: BatchSpanProcessor :: builder ( exporter)
114122 . with_batch_config (
115123 BatchConfigBuilder :: default ( )
116124 . with_max_queue_size ( crate :: constants:: OTEL_TRACE_BATCH_QUEUE_SIZE )
0 commit comments