@@ -17,28 +17,34 @@ limitations under the License.
1717use hyperlight_common:: flatbuffer_wrappers:: function_types:: { ParameterValue , ReturnType } ;
1818use rand:: Rng ;
1919use tracing:: { span, Level } ;
20- use tracing_subscriber:: util:: SubscriberInitExt ;
20+ use tracing_opentelemetry:: OpenTelemetryLayer ;
21+ use tracing_subscriber:: { layer:: SubscriberExt , util:: SubscriberInitExt } ;
2122extern crate hyperlight_host;
22- use std:: error:: Error ;
23- use std:: io:: stdin;
24- use std:: sync:: { Arc , Mutex } ;
25- use std:: thread:: { self , spawn, JoinHandle } ;
26-
2723use hyperlight_host:: sandbox:: uninitialized:: UninitializedSandbox ;
2824use hyperlight_host:: sandbox_state:: sandbox:: EvolvableSandbox ;
2925use hyperlight_host:: sandbox_state:: transition:: Noop ;
3026use hyperlight_host:: { GuestBinary , MultiUseSandbox , Result as HyperlightResult } ;
3127use hyperlight_testing:: simple_guest_as_string;
32- use opentelemetry:: global:: shutdown_tracer_provider;
33- use opentelemetry:: trace:: TracerProvider ;
34- use opentelemetry:: KeyValue ;
35- use opentelemetry_otlp:: { new_exporter, new_pipeline, WithExportConfig } ;
36- use opentelemetry_sdk:: runtime:: Tokio ;
37- use opentelemetry_sdk:: { trace, Resource } ;
38- use tracing_subscriber:: layer:: SubscriberExt ;
28+ use opentelemetry:: {
29+ global:: { self , shutdown_tracer_provider} ,
30+ trace:: TracerProvider ,
31+ KeyValue ,
32+ } ;
33+ use opentelemetry_otlp:: { SpanExporter , WithExportConfig } ;
34+ use opentelemetry_sdk:: { runtime:: Tokio , trace, Resource } ;
35+ use opentelemetry_semantic_conventions:: {
36+ attribute:: { SERVICE_NAME , SERVICE_VERSION } ,
37+ SCHEMA_URL ,
38+ } ;
39+ use std:: error:: Error ;
40+ use std:: io:: stdin;
41+ use std:: sync:: { Arc , Mutex } ;
42+ use std:: thread:: { self , spawn, JoinHandle } ;
3943use tracing_subscriber:: EnvFilter ;
4044use uuid:: Uuid ;
4145
46+ const ADDR : & str = "http://localhost:4317" ;
47+
4248fn fn_writer ( _msg : String ) -> HyperlightResult < i32 > {
4349 Ok ( 0 )
4450}
@@ -47,29 +53,43 @@ fn fn_writer(_msg: String) -> HyperlightResult<i32> {
4753
4854#[ tokio:: main]
4955async fn main ( ) -> Result < ( ) , Box < dyn Error + Send + Sync + ' static > > {
50- let tracer = new_pipeline ( )
51- . tracing ( )
52- . with_exporter (
53- new_exporter ( )
54- . tonic ( )
55- . with_endpoint ( "http://localhost:4317/v1/traces" ) ,
56+ init_tracing_subscriber ( ADDR ) ?;
57+
58+ Ok ( run_example ( ) ?)
59+ }
60+
61+ fn init_tracing_subscriber ( addr : & str ) -> Result < ( ) , Box < dyn Error + Send + Sync + ' static > > {
62+ let exporter = SpanExporter :: builder ( )
63+ . with_tonic ( )
64+ . with_endpoint ( addr)
65+ . build ( ) ?;
66+
67+ let provider = trace:: TracerProvider :: builder ( )
68+ . with_config (
69+ trace:: Config :: default ( ) . with_resource ( Resource :: from_schema_url (
70+ vec ! [
71+ KeyValue :: new( SERVICE_NAME , "hyperlight_otel_example" ) ,
72+ KeyValue :: new( SERVICE_VERSION , env!( "CARGO_PKG_VERSION" ) ) ,
73+ ] ,
74+ SCHEMA_URL ,
75+ ) ) ,
5676 )
57- . with_trace_config ( trace:: Config :: default ( ) . with_resource ( Resource :: new ( vec ! [
58- KeyValue :: new( "service.name" , "hyperlight_otel_example" ) ,
59- ] ) ) )
60- . install_batch ( Tokio )
61- . unwrap ( )
62- . tracer ( "trace-demo" ) ;
77+ . with_batch_exporter ( exporter, Tokio )
78+ . build ( ) ;
6379
64- let otel_layer = tracing_opentelemetry:: OpenTelemetryLayer :: new ( tracer) ;
80+ global:: set_tracer_provider ( provider. clone ( ) ) ;
81+ let tracer = provider. tracer ( "trace-demo" ) ;
6582
66- tracing_subscriber:: Registry :: default ( )
83+ let otel_layer = OpenTelemetryLayer :: new ( tracer) ;
84+
85+ tracing_subscriber:: registry ( )
6786 . with ( EnvFilter :: from_default_env ( ) )
6887 . with ( otel_layer)
6988 . try_init ( ) ?;
7089
71- Ok ( run_example ( ) ? )
90+ Ok ( ( ) )
7291}
92+
7393fn run_example ( ) -> HyperlightResult < ( ) > {
7494 // Get the path to a simple guest binary.
7595 let hyperlight_guest_path =
0 commit comments