@@ -24,9 +24,11 @@ use quickwit_cli::metrics::register_build_info_metric;
2424use quickwit_cli:: { busy_detector, install_default_crypto_ring_provider} ;
2525use quickwit_common:: runtimes:: scrape_tokio_runtime_metrics;
2626use quickwit_serve:: BuildInfo ;
27- use quickwit_telemetry_exporters:: TelemetryHandle ;
2827use tracing:: error;
2928
29+ #[ cfg( feature = "tokio-console" ) ]
30+ const QW_ENABLE_TOKIO_CONSOLE_ENV_KEY : & str = "QW_ENABLE_TOKIO_CONSOLE" ;
31+
3032/// The main tokio runtime takes num_cores / 3 threads by default, and can be overridden by the
3133/// QW_RUNTIME_NUM_THREADS environment variable.
3234fn get_main_runtime_num_threads ( ) -> usize {
@@ -46,8 +48,6 @@ fn main() -> anyhow::Result<()> {
4648 openssl_probe:: init_openssl_env_vars ( )
4749 } ;
4850
49- let ( command, ansi_colors) = parse_cli_command ( ) ;
50-
5151 let main_runtime_num_threads: usize = get_main_runtime_num_threads ( ) ;
5252 let rt = tokio:: runtime:: Builder :: new_multi_thread ( )
5353 . enable_all ( )
@@ -58,22 +58,7 @@ fn main() -> anyhow::Result<()> {
5858 . build ( )
5959 . context ( "failed to start main Tokio runtime" ) ?;
6060
61- rt. block_on ( async move {
62- install_default_crypto_ring_provider ( ) ;
63-
64- let build_info = BuildInfo :: get ( ) ;
65- let telemetry_handle = quickwit_telemetry_exporters:: init_telemetry (
66- & build_info. version ,
67- command. default_log_level ( ) ,
68- ansi_colors,
69- ) ?;
70- register_build_info_metric ( build_info) ;
71-
72- let runtime_handle = tokio:: runtime:: Handle :: current ( ) ;
73- scrape_tokio_runtime_metrics ( & runtime_handle, "main" ) ;
74-
75- main_impl ( command, telemetry_handle) . await
76- } )
61+ rt. block_on ( main_impl ( ) )
7762}
7863
7964fn parse_cli_command ( ) -> ( CliCommand , bool ) {
@@ -94,7 +79,37 @@ fn parse_cli_command() -> (CliCommand, bool) {
9479 ( command, ansi_colors)
9580}
9681
97- async fn main_impl ( command : CliCommand , telemetry_handle : TelemetryHandle ) -> anyhow:: Result < ( ) > {
82+ fn init_telemetry (
83+ service_version : & str ,
84+ level : tracing:: Level ,
85+ ansi_colors : bool ,
86+ ) -> anyhow:: Result < quickwit_telemetry_exporters:: TelemetryHandle > {
87+ #[ cfg( feature = "tokio-console" ) ]
88+ {
89+ if quickwit_common:: get_bool_from_env ( QW_ENABLE_TOKIO_CONSOLE_ENV_KEY , false ) {
90+ console_subscriber:: init ( ) ;
91+ return Ok ( quickwit_telemetry_exporters:: TelemetryHandle :: default ( ) ) ;
92+ }
93+ }
94+ quickwit_telemetry_exporters:: init_telemetry ( service_version, level, ansi_colors)
95+ }
96+
97+ async fn main_impl ( ) -> anyhow:: Result < ( ) > {
98+ let ( command, ansi_colors) = parse_cli_command ( ) ;
99+
100+ install_default_crypto_ring_provider ( ) ;
101+
102+ let build_info = BuildInfo :: get ( ) ;
103+ let telemetry_handle = init_telemetry (
104+ & build_info. version ,
105+ command. default_log_level ( ) ,
106+ ansi_colors,
107+ ) ?;
108+ register_build_info_metric ( build_info) ;
109+
110+ let runtime_handle = tokio:: runtime:: Handle :: current ( ) ;
111+ scrape_tokio_runtime_metrics ( & runtime_handle, "main" ) ;
112+
98113 #[ cfg( feature = "jemalloc" ) ]
99114 start_jemalloc_metrics_loop ( ) ;
100115
0 commit comments