diff --git a/lib/api-helper/build/src/macro_util.rs b/lib/api-helper/build/src/macro_util.rs index 7a71ceb4bf..563710c245 100644 --- a/lib/api-helper/build/src/macro_util.rs +++ b/lib/api-helper/build/src/macro_util.rs @@ -332,7 +332,6 @@ pub async fn __with_ctx( ts, ts, (), - Vec::new(), ); // Create auth diff --git a/lib/chirp/client/src/client.rs b/lib/chirp/client/src/client.rs index 8938167ea5..86fc5269cf 100644 --- a/lib/chirp/client/src/client.rs +++ b/lib/chirp/client/src/client.rs @@ -131,17 +131,6 @@ impl SharedClient { ts, ) } - - pub fn wrap_with( - self: Arc, - parent_req_id: Uuid, - ray_id: Uuid, - ts: i64, - trace: Vec, - perf_ctx: chirp_perf::PerfCtxInner, - ) -> Client { - Client::new(self, parent_req_id, ray_id, trace, Arc::new(perf_ctx), ts) - } } /// Used to communicate with other Chirp clients. @@ -238,6 +227,10 @@ impl Client { pub fn ts(&self) -> i64 { self.ts } + + pub fn trace(&self) -> &[chirp::TraceEntry] { + &self.trace + } } impl Drop for Client { diff --git a/lib/chirp/worker/src/manager.rs b/lib/chirp/worker/src/manager.rs index 19d42882e8..730afac63f 100644 --- a/lib/chirp/worker/src/manager.rs +++ b/lib/chirp/worker/src/manager.rs @@ -696,22 +696,16 @@ where let worker_req = { // Build client let ts = rivet_util::timestamp::now(); - let client = self.shared_client.clone().wrap_with( - req_id, - ray_id, - ts, - { - let mut x = trace.clone(); - x.push(chirp::TraceEntry { - context_name: worker_name.clone(), - req_id: req_id_proto.clone(), - ts: rivet_util::timestamp::now(), - run_context: chirp::RunContext::Service as i32, - }); - x - }, - chirp_perf::PerfCtxInner::new(self.redis_cache.clone(), ts, req_id, ray_id), - ); + let client = self.shared_client.clone().wrap(req_id, ray_id, { + let mut x = trace.clone(); + x.push(chirp::TraceEntry { + context_name: worker_name.clone(), + req_id: req_id_proto.clone(), + ts: rivet_util::timestamp::now(), + run_context: chirp::RunContext::Service as i32, + }); + x + }); let conn = Connection::new(client, self.pools.clone(), self.cache.clone()); let ts = req_debug @@ -743,7 +737,6 @@ where ts, req_ts, req_body, - trace, ), dont_log_body, allow_recursive, @@ -838,6 +831,8 @@ where .op_ctx .trace() .iter() + // Don't include the last trace event, which is the current request + .take(req.op_ctx.trace().len() - 1) .any(|x| x.context_name == req.op_ctx.name()); let handle_res = if is_recursive { Ok(Err(err_code!( diff --git a/lib/chirp/worker/src/test.rs b/lib/chirp/worker/src/test.rs index a8f65cbd8d..f41199c914 100644 --- a/lib/chirp/worker/src/test.rs +++ b/lib/chirp/worker/src/test.rs @@ -37,7 +37,6 @@ impl TestCtx { rivet_util::timestamp::now(), rivet_util::timestamp::now(), (), - Vec::new(), ); Ok(TestCtx { diff --git a/lib/connection/src/lib.rs b/lib/connection/src/lib.rs index 442f514397..4cded717f5 100644 --- a/lib/connection/src/lib.rs +++ b/lib/connection/src/lib.rs @@ -30,23 +30,24 @@ impl Connection { &self, parent_req_id: Uuid, ray_id: Uuid, - trace: Vec, - ) -> GlobalResult { + trace_entry: chirp_client::TraceEntry, + ) -> Connection { // Not the same as the operation ctx's ts because this cannot be overridden by debug start ts let ts = rivet_util::timestamp::now(); - let redis_cache = self.pools.redis("ephemeral")?; - Ok(Connection::new( - (*self.client).clone().wrap_with( + Connection::new( + (*self.client).clone().wrap( parent_req_id, ray_id, - ts, - trace, - chirp_perf::PerfCtxInner::new(redis_cache, ts, parent_req_id, ray_id), + { + let mut x = self.client.trace().to_vec(); + x.push(trace_entry); + x + }, ), self.pools.clone(), self.cache.clone(), - )) + ) } pub fn chirp(&self) -> &chirp_client::Client { diff --git a/lib/operation/core/src/lib.rs b/lib/operation/core/src/lib.rs index 90bb750ca1..d2706d9e19 100644 --- a/lib/operation/core/src/lib.rs +++ b/lib/operation/core/src/lib.rs @@ -40,9 +40,6 @@ where ts: i64, req_ts: i64, body: B, - // Trace of all requests not including this request. The client does include - // this request in the trace, though. - trace: Vec, } impl OperationContext @@ -58,7 +55,6 @@ where ts: i64, req_ts: i64, body: B, - trace: Vec, ) -> Self { OperationContext { name, @@ -69,7 +65,6 @@ where ts, req_ts, body, - trace, } } @@ -90,7 +85,7 @@ where // TODO: Throw dedicated "timed out" error here // Process the request - let req_op_ctx = self.wrap::(body)?; + let req_op_ctx = self.wrap::(body); let timeout_fut = tokio::time::timeout(O::TIMEOUT, O::handle(req_op_ctx).in_current_span()); let res = tokio::task::Builder::new() .name("operation::handle") @@ -134,49 +129,28 @@ where } /// Adds trace and correctly wraps `Connection` (and subsequently `chirp_client::Client`). - fn wrap(&self, body: O::Request) -> GlobalResult> { - let ray_id = Uuid::new_v4(); - // Add self to new operation's trace - let trace = { - let mut x = self.trace.clone(); - x.push(chirp_client::TraceEntry { - context_name: self.name.clone(), - req_id: Some(self.req_id.into()), - ts: rivet_util::timestamp::now(), - run_context: match rivet_util::env::run_context() { - rivet_util::env::RunContext::Service => chirp_client::RunContext::Service, - rivet_util::env::RunContext::Test => chirp_client::RunContext::Test, - } as i32, - }); - x + fn wrap(&self, body: O::Request) -> OperationContext { + let req_id = Uuid::new_v4(); + let trace_entry = chirp_client::TraceEntry { + context_name: O::NAME.to_string(), + req_id: Some(req_id.into()), + ts: rivet_util::timestamp::now(), + run_context: match rivet_util::env::run_context() { + rivet_util::env::RunContext::Service => chirp_client::RunContext::Service, + rivet_util::env::RunContext::Test => chirp_client::RunContext::Test, + } as i32, }; - Ok(OperationContext { + OperationContext { name: O::NAME.to_string(), timeout: O::TIMEOUT, - conn: self.conn.wrap(self.req_id, ray_id, { - let mut x = trace.clone(); - - // Add new operation's trace to its connection (and chirp client) - x.push(chirp_client::TraceEntry { - context_name: O::NAME.to_string(), - req_id: Some(self.req_id.into()), - ts: rivet_util::timestamp::now(), - run_context: match rivet_util::env::run_context() { - rivet_util::env::RunContext::Service => chirp_client::RunContext::Service, - rivet_util::env::RunContext::Test => chirp_client::RunContext::Test, - } as i32, - }); - - x - })?, - req_id: self.req_id, - ray_id, + conn: self.conn.wrap(req_id, self.ray_id, trace_entry), + req_id, + ray_id: self.ray_id, ts: util::timestamp::now(), req_ts: self.req_ts, body, - trace, - }) + } } /// Clones everything but the body. This should always be used over `.clone()` unless you need to @@ -191,7 +165,6 @@ where ts: self.ts, req_ts: self.req_ts, body: (), - trace: self.trace.clone(), } } @@ -231,11 +204,11 @@ where } pub fn trace(&self) -> &[chirp_client::TraceEntry] { - &self.trace + self.conn.trace() } pub fn test(&self) -> bool { - self.trace + self.trace() .iter() .any(|x| x.run_context == chirp_client::RunContext::Test as i32) } diff --git a/svc/api/admin/tests/basic.rs b/svc/api/admin/tests/basic.rs index f1bba87663..d614faefc7 100644 --- a/svc/api/admin/tests/basic.rs +++ b/svc/api/admin/tests/basic.rs @@ -39,7 +39,6 @@ impl Ctx { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); Ctx { op_ctx } diff --git a/svc/api/auth/tests/basic.rs b/svc/api/auth/tests/basic.rs index 2955dfc67e..0ff59d86c9 100644 --- a/svc/api/auth/tests/basic.rs +++ b/svc/api/auth/tests/basic.rs @@ -46,7 +46,6 @@ // util::timestamp::now(), // util::timestamp::now(), // (), -// Vec::new(), // ); // let (user_id, user_token) = Self::issue_user_token(&op_ctx).await; diff --git a/svc/api/cf-verification/tests/basic.rs b/svc/api/cf-verification/tests/basic.rs index 12bf6704ba..63bb907339 100644 --- a/svc/api/cf-verification/tests/basic.rs +++ b/svc/api/cf-verification/tests/basic.rs @@ -37,7 +37,6 @@ // util::timestamp::now(), // util::timestamp::now(), // (), -// Vec::new(), // ); // let http_client = rivet_cf_verification::Config::builder() diff --git a/svc/api/cloud/tests/basic.rs b/svc/api/cloud/tests/basic.rs index 596f2cf159..ce98bf4f32 100644 --- a/svc/api/cloud/tests/basic.rs +++ b/svc/api/cloud/tests/basic.rs @@ -46,7 +46,6 @@ // util::timestamp::now(), // util::timestamp::now(), // (), -// Vec::new(), // ); // // Create temp team diff --git a/svc/api/group/tests/basic.rs b/svc/api/group/tests/basic.rs index 8f31faecf3..cbab0367e3 100644 --- a/svc/api/group/tests/basic.rs +++ b/svc/api/group/tests/basic.rs @@ -40,7 +40,6 @@ impl Ctx { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let (_user_id, user_token) = Self::issue_user_token(&op_ctx).await; diff --git a/svc/api/identity/tests/basic.rs b/svc/api/identity/tests/basic.rs index 7df9cabe0a..4401fd085a 100644 --- a/svc/api/identity/tests/basic.rs +++ b/svc/api/identity/tests/basic.rs @@ -47,7 +47,6 @@ // util::timestamp::now(), // util::timestamp::now(), // (), -// Vec::new(), // ); // let (primary_region_id, _) = Self::setup_region(&op_ctx).await; diff --git a/svc/api/job/tests/basic.rs b/svc/api/job/tests/basic.rs index 6caa1f7a05..dfb4ba24ed 100644 --- a/svc/api/job/tests/basic.rs +++ b/svc/api/job/tests/basic.rs @@ -41,7 +41,6 @@ // util::timestamp::now(), // util::timestamp::now(), // (), -// Vec::new(), // ); // let nomad_config = nomad_util::config_from_env().unwrap(); diff --git a/svc/api/kv/tests/basic.rs b/svc/api/kv/tests/basic.rs index 009ede160c..c7a9641405 100644 --- a/svc/api/kv/tests/basic.rs +++ b/svc/api/kv/tests/basic.rs @@ -52,7 +52,6 @@ // util::timestamp::now(), // util::timestamp::now(), // (), -// Vec::new(), // ); // let (primary_region_id, _) = Self::setup_region(&op_ctx).await; diff --git a/svc/api/matchmaker/tests/common.rs b/svc/api/matchmaker/tests/common.rs index 5b6fa9803b..affa697dce 100644 --- a/svc/api/matchmaker/tests/common.rs +++ b/svc/api/matchmaker/tests/common.rs @@ -56,7 +56,6 @@ impl Ctx { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let (primary_region_id, primary_region_name_id) = Self::setup_region(&op_ctx).await; diff --git a/svc/api/portal/tests/basic.rs b/svc/api/portal/tests/basic.rs index d8f1d02b83..9c18736520 100644 --- a/svc/api/portal/tests/basic.rs +++ b/svc/api/portal/tests/basic.rs @@ -39,7 +39,6 @@ impl Ctx { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let (_user_id, user_token) = Self::issue_user_token(&op_ctx).await; diff --git a/svc/api/status/tests/basic.rs b/svc/api/status/tests/basic.rs index f9d9f5867f..4055c30800 100644 --- a/svc/api/status/tests/basic.rs +++ b/svc/api/status/tests/basic.rs @@ -40,7 +40,6 @@ // util::timestamp::now(), // util::timestamp::now(), // (), -// Vec::new(), // ); // let http_client = rivet_status::Config::builder() diff --git a/svc/api/traefik-provider/tests/basic.rs b/svc/api/traefik-provider/tests/basic.rs index 84e1f3a6df..42bd1d277f 100644 --- a/svc/api/traefik-provider/tests/basic.rs +++ b/svc/api/traefik-provider/tests/basic.rs @@ -53,7 +53,6 @@ impl Ctx { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); Ctx { op_ctx } diff --git a/svc/pkg/build/standalone/default-create/src/lib.rs b/svc/pkg/build/standalone/default-create/src/lib.rs index 350d388e71..121712d52f 100644 --- a/svc/pkg/build/standalone/default-create/src/lib.rs +++ b/svc/pkg/build/standalone/default-create/src/lib.rs @@ -82,7 +82,6 @@ pub async fn run_from_env() -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); for build in DEFAULT_BUILDS { diff --git a/svc/pkg/cluster/standalone/datacenter-tls-renew/src/lib.rs b/svc/pkg/cluster/standalone/datacenter-tls-renew/src/lib.rs index 75c8108d3d..6e4a489a53 100644 --- a/svc/pkg/cluster/standalone/datacenter-tls-renew/src/lib.rs +++ b/svc/pkg/cluster/standalone/datacenter-tls-renew/src/lib.rs @@ -19,7 +19,6 @@ pub async fn run_from_env(pools: rivet_pools::Pools) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let updated_datacenter_ids = rivet_pools::utils::crdb::tx(&ctx.crdb().await?, |tx| { diff --git a/svc/pkg/cluster/standalone/default-update/src/lib.rs b/svc/pkg/cluster/standalone/default-update/src/lib.rs index ef4d503c77..f0a3e4e2c2 100644 --- a/svc/pkg/cluster/standalone/default-update/src/lib.rs +++ b/svc/pkg/cluster/standalone/default-update/src/lib.rs @@ -111,7 +111,6 @@ pub async fn run_from_env(use_autoscaler: bool) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); // Read config from env diff --git a/svc/pkg/cluster/standalone/fix-tls/src/lib.rs b/svc/pkg/cluster/standalone/fix-tls/src/lib.rs index 6e2841c425..cbfa37ccc6 100644 --- a/svc/pkg/cluster/standalone/fix-tls/src/lib.rs +++ b/svc/pkg/cluster/standalone/fix-tls/src/lib.rs @@ -40,7 +40,6 @@ pub async fn run_from_env(ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let datacenter_ids = vec!["5767a802-5c7c-4563-a266-33c014f7e244"] diff --git a/svc/pkg/cluster/standalone/gc/src/lib.rs b/svc/pkg/cluster/standalone/gc/src/lib.rs index f8c4a8dc0c..b520f539ef 100644 --- a/svc/pkg/cluster/standalone/gc/src/lib.rs +++ b/svc/pkg/cluster/standalone/gc/src/lib.rs @@ -23,7 +23,6 @@ pub async fn run_from_env(ts: i64, pools: rivet_pools::Pools) -> GlobalResult<() util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let datacenter_ids = rivet_pools::utils::crdb::tx(&ctx.crdb().await?, |tx| { diff --git a/svc/pkg/cluster/standalone/metrics-publish/src/lib.rs b/svc/pkg/cluster/standalone/metrics-publish/src/lib.rs index 86cfbfcf2e..c5770f1812 100644 --- a/svc/pkg/cluster/standalone/metrics-publish/src/lib.rs +++ b/svc/pkg/cluster/standalone/metrics-publish/src/lib.rs @@ -57,7 +57,6 @@ pub async fn run_from_env(_ts: i64, pools: rivet_pools::Pools) -> GlobalResult<( util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let servers = select_servers(&ctx).await?; diff --git a/svc/pkg/job/standalone/gc/src/lib.rs b/svc/pkg/job/standalone/gc/src/lib.rs index f3cf545e46..1d93bacdf0 100644 --- a/svc/pkg/job/standalone/gc/src/lib.rs +++ b/svc/pkg/job/standalone/gc/src/lib.rs @@ -42,7 +42,6 @@ pub async fn run_from_env(ts: i64, pools: rivet_pools::Pools) -> GlobalResult<() ts, ts, (), - Vec::new(), ); // Find jobs to stop. diff --git a/svc/pkg/linode/standalone/gc/src/lib.rs b/svc/pkg/linode/standalone/gc/src/lib.rs index 5437414708..de7d1279c3 100644 --- a/svc/pkg/linode/standalone/gc/src/lib.rs +++ b/svc/pkg/linode/standalone/gc/src/lib.rs @@ -29,7 +29,6 @@ pub async fn run_from_env(pools: rivet_pools::Pools) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let dc_rows = sql_fetch_all!( diff --git a/svc/pkg/load-test/standalone/api-cloud/src/lib.rs b/svc/pkg/load-test/standalone/api-cloud/src/lib.rs index c07d88510c..b24ea06526 100644 --- a/svc/pkg/load-test/standalone/api-cloud/src/lib.rs +++ b/svc/pkg/load-test/standalone/api-cloud/src/lib.rs @@ -18,7 +18,6 @@ pub async fn run_from_env(_ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); // Create temp team diff --git a/svc/pkg/load-test/standalone/mm-sustain/src/lib.rs b/svc/pkg/load-test/standalone/mm-sustain/src/lib.rs index 28dc9fa51b..5c128216fa 100644 --- a/svc/pkg/load-test/standalone/mm-sustain/src/lib.rs +++ b/svc/pkg/load-test/standalone/mm-sustain/src/lib.rs @@ -22,7 +22,6 @@ pub async fn run_from_env(_ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); // Region diff --git a/svc/pkg/load-test/standalone/mm/src/lib.rs b/svc/pkg/load-test/standalone/mm/src/lib.rs index fd5a93bde2..8d4b3dcd58 100644 --- a/svc/pkg/load-test/standalone/mm/src/lib.rs +++ b/svc/pkg/load-test/standalone/mm/src/lib.rs @@ -72,7 +72,6 @@ pub async fn run_from_env(_ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); // Setup diff --git a/svc/pkg/load-test/standalone/sqlx/src/lib.rs b/svc/pkg/load-test/standalone/sqlx/src/lib.rs index 00b7009854..51d2598f47 100644 --- a/svc/pkg/load-test/standalone/sqlx/src/lib.rs +++ b/svc/pkg/load-test/standalone/sqlx/src/lib.rs @@ -14,7 +14,6 @@ pub async fn run_from_env(_ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let mut interval = tokio::time::interval(std::time::Duration::from_millis(100)); diff --git a/svc/pkg/load-test/standalone/watch-requests/src/lib.rs b/svc/pkg/load-test/standalone/watch-requests/src/lib.rs index e713c689e8..adc761fc4c 100644 --- a/svc/pkg/load-test/standalone/watch-requests/src/lib.rs +++ b/svc/pkg/load-test/standalone/watch-requests/src/lib.rs @@ -18,7 +18,6 @@ pub async fn run_from_env(_ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); // Create temp team diff --git a/svc/pkg/mm/standalone/gc/src/lib.rs b/svc/pkg/mm/standalone/gc/src/lib.rs index cd728135a4..0695a8a64c 100644 --- a/svc/pkg/mm/standalone/gc/src/lib.rs +++ b/svc/pkg/mm/standalone/gc/src/lib.rs @@ -15,7 +15,6 @@ pub async fn run_from_env(ts: i64, pools: rivet_pools::Pools) -> GlobalResult<() ts, ts, (), - Vec::new(), ); let redis_mm = ctx.redis_mm().await?; diff --git a/svc/pkg/telemetry/standalone/beacon/src/lib.rs b/svc/pkg/telemetry/standalone/beacon/src/lib.rs index 505671ca44..dc0167acbb 100644 --- a/svc/pkg/telemetry/standalone/beacon/src/lib.rs +++ b/svc/pkg/telemetry/standalone/beacon/src/lib.rs @@ -28,7 +28,6 @@ pub async fn run_from_env(ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); if std::env::var("RIVET_TELEMETRY_DISABLE") diff --git a/svc/pkg/upload/standalone/provider-fill/src/lib.rs b/svc/pkg/upload/standalone/provider-fill/src/lib.rs index 230638b7b4..1ff012e6c2 100644 --- a/svc/pkg/upload/standalone/provider-fill/src/lib.rs +++ b/svc/pkg/upload/standalone/provider-fill/src/lib.rs @@ -17,7 +17,6 @@ pub async fn run_from_env() -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let Ok(backfill_provider) = std::env::var("S3_BACKFILL_PROVIDER") else { diff --git a/svc/pkg/user/standalone/delete-pending/src/lib.rs b/svc/pkg/user/standalone/delete-pending/src/lib.rs index 055bbdf23f..c3b8fbd63c 100644 --- a/svc/pkg/user/standalone/delete-pending/src/lib.rs +++ b/svc/pkg/user/standalone/delete-pending/src/lib.rs @@ -18,7 +18,6 @@ pub async fn run_from_env(ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let user_ids = sql_fetch_all!( diff --git a/svc/pkg/user/standalone/search-user-gc/src/lib.rs b/svc/pkg/user/standalone/search-user-gc/src/lib.rs index bb86ebe18d..c0a7d04644 100644 --- a/svc/pkg/user/standalone/search-user-gc/src/lib.rs +++ b/svc/pkg/user/standalone/search-user-gc/src/lib.rs @@ -18,7 +18,6 @@ pub async fn run_from_env(ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); let mut total_removed = 0; diff --git a/svc/templates/api/tests/basic.rs b/svc/templates/api/tests/basic.rs index 2f3f541ed8..a8bd083d42 100644 --- a/svc/templates/api/tests/basic.rs +++ b/svc/templates/api/tests/basic.rs @@ -37,7 +37,6 @@ impl Ctx { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); Ctx { op_ctx } diff --git a/svc/templates/standalone/src/lib.rs b/svc/templates/standalone/src/lib.rs index a46d1d1d6b..8b67c55860 100644 --- a/svc/templates/standalone/src/lib.rs +++ b/svc/templates/standalone/src/lib.rs @@ -15,7 +15,6 @@ pub async fn run_from_env(ts: i64) -> GlobalResult<()> { util::timestamp::now(), util::timestamp::now(), (), - Vec::new(), ); todo!();