@@ -3,7 +3,7 @@ use fhevm_engine_common::keys::{FhevmKeys, SerializedFhevmKeys};
33use fhevm_engine_common:: { healthz_server, metrics_server, telemetry} ;
44use tokio_util:: sync:: CancellationToken ;
55
6- use std:: sync:: Once ;
6+ use std:: sync:: { Once , OnceLock } ;
77use tokio:: task:: JoinSet ;
88
99pub mod daemon_cli;
@@ -49,29 +49,31 @@ pub fn start_runtime(
4949
5050// Used for testing as we would call `async_main()` multiple times.
5151static TRACING_INIT : Once = Once :: new ( ) ;
52+ static OTLP_SETUP_ERROR : OnceLock < String > = OnceLock :: new ( ) ;
53+ static OTEL_GUARD : OnceLock < Option < telemetry:: TracerProviderGuard > > = OnceLock :: new ( ) ;
5254
5355pub async fn async_main (
5456 args : daemon_cli:: Args ,
5557) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync > > {
5658 TRACING_INIT . call_once ( || {
57- tracing_subscriber:: fmt ( )
58- . json ( )
59- . with_level ( true )
60- . with_max_level ( args. log_level )
61- . init ( ) ;
59+ let otel_guard =
60+ match telemetry:: init_json_subscriber ( args. log_level , & args. service_name , "otlp-layer" )
61+ {
62+ Ok ( guard) => guard,
63+ Err ( err) => {
64+ let _ = OTLP_SETUP_ERROR . set ( err. to_string ( ) ) ;
65+ None
66+ }
67+ } ;
68+ let _ = OTEL_GUARD . set ( otel_guard) ;
6269 } ) ;
70+ if let Some ( err) = OTLP_SETUP_ERROR . get ( ) {
71+ error ! ( error = %err, "Failed to setup OTLP" ) ;
72+ }
6373
6474 let cancel_token = CancellationToken :: new ( ) ;
6575 info ! ( target: "async_main" , args = ?args, "Starting runtime with args" ) ;
6676
67- let _otel_guard = match telemetry:: init_otel ( & args. service_name ) {
68- Ok ( otel_guard) => otel_guard,
69- Err ( err) => {
70- error ! ( error = %err, "Failed to setup OTLP" ) ;
71- None
72- }
73- } ;
74-
7577 let database_url = args. database_url . clone ( ) . unwrap_or_default ( ) ;
7678 let health_check = health_check:: HealthCheck :: new ( database_url) ;
7779
0 commit comments