@@ -16,6 +16,8 @@ use crates_io::Emails;
1616use crates_io:: cloudfront:: CloudFront ;
1717use crates_io:: config:: SharedConfig ;
1818use crates_io:: db;
19+ use crates_io:: metrics:: consts:: METER_NAME ;
20+ use crates_io:: metrics:: { WorkerMetrics , meter_provider} ;
1921use crates_io:: ssh;
2022use crates_io:: storage:: Storage ;
2123use crates_io:: worker:: { RunnerExt , WorkerContext } ;
@@ -56,6 +58,10 @@ pub fn run() -> anyhow::Result<()> {
5658 // increase the statement timeout a bit…
5759 config. db . primary . statement_timeout = Duration :: from_secs ( 4 * 60 * 60 ) ;
5860
61+ let meter_provider = meter_provider ( & config) ;
62+ let meter = meter_provider. meter ( METER_NAME ) ;
63+ let worker_metrics = WorkerMetrics :: new ( & meter) ;
64+
5965 let runtime = tokio:: runtime:: Builder :: new_multi_thread ( )
6066 . enable_all ( )
6167 . build ( )
@@ -79,7 +85,9 @@ pub fn run() -> anyhow::Result<()> {
7985
8086 let user_agent = crates_io_version:: user_agent ( ) ;
8187 let http_client = Client :: builder ( ) . user_agent ( user_agent) . build ( ) ?;
82- let datadog = config. datadog . client ( http_client. clone ( ) ) . map ( Arc :: new) ;
88+ let datadog = ( !config. metrics . otlp_enabled )
89+ . then ( || config. datadog . client ( http_client. clone ( ) ) . map ( Arc :: new) )
90+ . flatten ( ) ;
8391
8492 let cloudfront = CloudFront :: from_environment ( ) ;
8593 let storage = Arc :: new ( Storage :: from_config ( & config. storage ) ) ;
@@ -103,9 +111,11 @@ pub fn run() -> anyhow::Result<()> {
103111 let sync_github_app = build_sync_github_app ( ) ?;
104112
105113 let deadpool = db:: create_pool ( & config. db . primary ) ;
114+ worker_metrics. track_db_pool ( "worker" , & deadpool) ;
106115
107116 let ctx = WorkerContext :: builder ( )
108117 . config ( Arc :: new ( config) )
118+ . metrics ( worker_metrics)
109119 . repository_config ( repository_config)
110120 . maybe_cloudfront ( cloudfront)
111121 . maybe_fastly ( fastly)
@@ -143,7 +153,12 @@ pub fn run() -> anyhow::Result<()> {
143153
144154 runtime. block_on ( async {
145155 let handle = runner. start ( ) ;
146- crates_io:: metrics:: datadog:: spawn ( & ctx. config , ctx. deadpool . clone ( ) , datadog) ;
156+ crates_io:: metrics:: datadog:: spawn (
157+ & ctx. config ,
158+ ctx. deadpool . clone ( ) ,
159+ ctx. metrics . clone ( ) ,
160+ datadog,
161+ ) ;
147162
148163 info ! ( "Runner booted, running jobs" ) ;
149164 handle. wait_for_shutdown ( ) . await
0 commit comments