File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,10 @@ use std::sync::Arc;
5555use temporal_client:: { ConfiguredClient , TemporalServiceClientWithMetrics } ;
5656use temporal_sdk_core_api:: {
5757 errors:: { CompleteActivityError , PollActivityError , PollWfError } ,
58- telemetry:: { metrics:: TemporalMeter , TelemetryOptions } ,
58+ telemetry:: {
59+ metrics:: { CoreMeter , TemporalMeter } ,
60+ TelemetryOptions ,
61+ } ,
5962 Worker as WorkerTrait ,
6063} ;
6164use temporal_sdk_core_protos:: coresdk:: ActivityHeartbeat ;
@@ -278,6 +281,12 @@ impl CoreRuntime {
278281 pub fn telemetry ( & self ) -> & TelemetryInstance {
279282 & self . telemetry
280283 }
284+
285+ /// Some metric meters cannot be initialized until after a tokio runtime has started and after
286+ /// other telemetry has initted (ex: prometheus). They can be attached here.
287+ pub fn attach_late_init_metrics ( & mut self , meter : Arc < dyn CoreMeter + ' static > ) {
288+ self . telemetry . attach_late_init_metrics ( meter)
289+ }
281290}
282291
283292impl Drop for CoreRuntime {
Original file line number Diff line number Diff line change @@ -77,6 +77,12 @@ impl TelemetryInstance {
7777 self . trace_subscriber . clone ( )
7878 }
7979
80+ /// Some metric meters cannot be initialized until after a tokio runtime has started and after
81+ /// other telemetry has initted (ex: prometheus). They can be attached here.
82+ pub fn attach_late_init_metrics ( & mut self , meter : Arc < dyn CoreMeter + ' static > ) {
83+ self . metrics = Some ( meter) ;
84+ }
85+
8086 /// Returns our wrapper for metric meters, can be used to, ex: initialize clients
8187 pub fn get_metric_meter ( & self ) -> Option < TemporalMeter > {
8288 self . metrics . clone ( ) . map ( |m| {
Original file line number Diff line number Diff line change @@ -423,3 +423,30 @@ async fn query_of_closed_workflow_doesnt_tick_terminal_metric(
423423 . expect ( "Must find matching metric" ) ;
424424 assert ! ( matching_line. ends_with( '1' ) ) ;
425425}
426+
427+ #[ test]
428+ fn runtime_new ( ) {
429+ let mut rt = CoreRuntime :: new (
430+ get_integ_telem_options ( ) ,
431+ tokio:: runtime:: Builder :: new_multi_thread ( ) ,
432+ )
433+ . unwrap ( ) ;
434+ let handle = rt. tokio_handle ( ) ;
435+ let _rt = handle. enter ( ) ;
436+ let ( telemopts, addr, _aborter) = prom_metrics ( ) ;
437+ rt. attach_late_init_metrics ( telemopts. metrics . unwrap ( ) ) ;
438+ let opts = get_integ_server_options ( ) ;
439+ handle. block_on ( async {
440+ let mut raw_client = opts
441+ . connect_no_namespace ( rt. metric_meter ( ) , None )
442+ . await
443+ . unwrap ( ) ;
444+ assert ! ( raw_client. get_client( ) . capabilities( ) . is_some( ) ) ;
445+ let _ = raw_client
446+ . list_namespaces ( ListNamespacesRequest :: default ( ) )
447+ . await
448+ . unwrap ( ) ;
449+ let body = get_text ( format ! ( "http://{addr}/metrics" ) ) . await ;
450+ assert ! ( body. contains( "temporal_request" ) ) ;
451+ } ) ;
452+ }
You can’t perform that action at this time.
0 commit comments