diff --git a/packages/common/api-util/src/lib.rs b/packages/common/api-util/src/lib.rs index dbfa23fc6f..dc598723dc 100644 --- a/packages/common/api-util/src/lib.rs +++ b/packages/common/api-util/src/lib.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use axum::{body::Body, response::Response}; use futures_util::StreamExt; use rivet_api_builder::{ApiCtx, ErrorResponse, RawErrorResponse}; -use serde::{Serialize, de::DeserializeOwned}; +use serde::{de::DeserializeOwned, Serialize}; use std::future::Future; mod errors; @@ -10,6 +10,7 @@ mod errors; pub use axum::http::{HeaderMap, Method}; /// Generic function to make raw requests to remote datacenters by label (returns axum Response) +#[tracing::instrument(skip(ctx, headers, query, body))] pub async fn request_remote_datacenter_raw( ctx: &ApiCtx, dc_label: u16, @@ -32,6 +33,8 @@ pub async fn request_remote_datacenter_raw( url.set_query(Some(&serde_html_form::to_string(q)?)); } + tracing::debug!(%method, %url, "sending raw request to remote datacenter"); + let mut request = client.request(method, url).headers(headers); if let Some(b) = body { @@ -48,6 +51,7 @@ pub async fn request_remote_datacenter_raw( } /// Generic function to make requests to a specific datacenter +#[tracing::instrument(skip(config, headers, query, body))] pub async fn request_remote_datacenter( config: &rivet_config::Config, dc_label: u16, @@ -72,6 +76,8 @@ where url.set_query(Some(&serde_html_form::to_string(q)?)); } + tracing::debug!(%method, %url, "sending request to remote datacenter"); + let mut request = client.request(method, url).headers(headers); if let Some(b) = body { @@ -89,6 +95,7 @@ where /// Generic function to fanout requests to all datacenters and aggregate results /// Returns aggregated results and errors only if all requests fail +#[tracing::instrument(skip(ctx, headers, query, local_handler, aggregator))] pub async fn fanout_to_datacenters( ctx: ApiCtx, headers: HeaderMap, @@ -164,6 +171,7 @@ where Ok(aggregated) } +#[tracing::instrument(skip_all)] pub async fn reqwest_to_axum_response(reqwest_response: reqwest::Response) -> Result { let status = reqwest_response.status(); let headers = reqwest_response.headers().clone(); @@ -178,6 +186,7 @@ pub async fn reqwest_to_axum_response(reqwest_response: reqwest::Response) -> Re Ok(response) } +#[tracing::instrument(skip_all)] pub async fn parse_response(reqwest_response: reqwest::Response) -> Result { let status = reqwest_response.status(); let response_text = reqwest_response.text().await?; diff --git a/packages/core/api-peer/src/actors/create.rs b/packages/core/api-peer/src/actors/create.rs index ebf91f98eb..5f632ba7d3 100644 --- a/packages/core/api-peer/src/actors/create.rs +++ b/packages/core/api-peer/src/actors/create.rs @@ -3,6 +3,7 @@ use gas::prelude::*; use rivet_api_builder::ApiCtx; use rivet_api_types::actors::create::{CreateQuery, CreateRequest, CreateResponse}; +#[tracing::instrument(skip_all)] pub async fn create( ctx: ApiCtx, _path: (), diff --git a/packages/core/api-peer/src/actors/delete.rs b/packages/core/api-peer/src/actors/delete.rs index db12833034..afb5c3486c 100644 --- a/packages/core/api-peer/src/actors/delete.rs +++ b/packages/core/api-peer/src/actors/delete.rs @@ -34,6 +34,7 @@ pub struct DeletePath { (status = 200, body = DeleteResponse), ), )] +#[tracing::instrument(skip_all)] pub async fn delete(ctx: ApiCtx, path: DeletePath, query: DeleteQuery) -> Result { // Get the actor first to verify it exists let actors_res = ctx diff --git a/packages/core/api-peer/src/actors/list.rs b/packages/core/api-peer/src/actors/list.rs index 3009785571..6291e58caf 100644 --- a/packages/core/api-peer/src/actors/list.rs +++ b/packages/core/api-peer/src/actors/list.rs @@ -11,6 +11,7 @@ use rivet_api_types::{actors::list::*, pagination::Pagination}; (status = 200, body = ListResponse), ), )] +#[tracing::instrument(skip_all)] pub async fn list(ctx: ApiCtx, _path: (), query: ListQuery) -> Result { let key = query.key; let actor_ids = query.actor_ids.as_ref().map(|x| { diff --git a/packages/core/api-peer/src/actors/list_names.rs b/packages/core/api-peer/src/actors/list_names.rs index bf8076ba49..f6122278bf 100644 --- a/packages/core/api-peer/src/actors/list_names.rs +++ b/packages/core/api-peer/src/actors/list_names.rs @@ -12,6 +12,7 @@ use rivet_types::actors::ActorName; (status = 200, body = ListNamesResponse), ), )] +#[tracing::instrument(skip_all)] pub async fn list_names( ctx: ApiCtx, _path: (), diff --git a/packages/core/api-peer/src/internal.rs b/packages/core/api-peer/src/internal.rs index 3aa04b075e..2ebfa04073 100644 --- a/packages/core/api-peer/src/internal.rs +++ b/packages/core/api-peer/src/internal.rs @@ -12,6 +12,7 @@ pub struct CachePurgeRequest { #[derive(Serialize)] pub struct CachePurgeResponse {} +#[tracing::instrument(skip_all)] pub async fn cache_purge( ctx: ApiCtx, _path: (), @@ -30,6 +31,7 @@ pub async fn cache_purge( #[derive(Serialize)] pub struct BumpServerlessAutoscalerResponse {} +#[tracing::instrument(skip_all)] pub async fn bump_serverless_autoscaler( ctx: ApiCtx, _path: (), diff --git a/packages/core/api-peer/src/lib.rs b/packages/core/api-peer/src/lib.rs index 26df5c474a..495124a843 100644 --- a/packages/core/api-peer/src/lib.rs +++ b/packages/core/api-peer/src/lib.rs @@ -11,6 +11,7 @@ pub mod runners; pub use router::router as create_router; +#[tracing::instrument(skip_all)] pub async fn start(config: rivet_config::Config, pools: rivet_pools::Pools) -> Result<()> { let host = config.api_peer().host(); let port = config.api_peer().port(); diff --git a/packages/core/api-peer/src/namespaces.rs b/packages/core/api-peer/src/namespaces.rs index 16c3e88a00..2368d52a22 100644 --- a/packages/core/api-peer/src/namespaces.rs +++ b/packages/core/api-peer/src/namespaces.rs @@ -6,6 +6,7 @@ use rivet_util::Id; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; +#[tracing::instrument(skip_all)] pub async fn list(ctx: ApiCtx, _path: (), query: ListQuery) -> Result { let namespace_ids = query.namespace_ids.as_ref().map(|x| { x.split(',') @@ -72,6 +73,7 @@ pub struct CreateResponse { pub namespace: rivet_types::namespaces::Namespace, } +#[tracing::instrument(skip_all)] pub async fn create( ctx: ApiCtx, _path: (), diff --git a/packages/core/api-peer/src/router.rs b/packages/core/api-peer/src/router.rs index 5e9a359c9f..06c02aa7d1 100644 --- a/packages/core/api-peer/src/router.rs +++ b/packages/core/api-peer/src/router.rs @@ -2,6 +2,7 @@ use rivet_api_builder::{create_router, prelude::*}; use crate::{actors, internal, namespaces, runner_configs, runners}; +#[tracing::instrument(skip_all)] pub async fn router( name: &'static str, config: rivet_config::Config, diff --git a/packages/core/api-peer/src/runner_configs.rs b/packages/core/api-peer/src/runner_configs.rs index 6b6da50f24..fa992d7d02 100644 --- a/packages/core/api-peer/src/runner_configs.rs +++ b/packages/core/api-peer/src/runner_configs.rs @@ -6,6 +6,7 @@ use rivet_types::keys::namespace::runner_config::RunnerConfigVariant; use serde::{Deserialize, Serialize}; use utoipa::{IntoParams, ToSchema}; +#[tracing::instrument(skip_all)] pub async fn list(ctx: ApiCtx, _path: ListPath, query: ListQuery) -> Result { let namespace = ctx .op(namespace::ops::resolve_for_name_global::Input { @@ -94,6 +95,7 @@ pub struct UpsertRequest(pub rivet_api_types::namespaces::runner_configs::Runner #[schema(as = RunnerConfigsUpsertResponse)] pub struct UpsertResponse {} +#[tracing::instrument(skip_all)] pub async fn upsert( ctx: ApiCtx, path: UpsertPath, @@ -134,6 +136,7 @@ pub struct DeletePath { #[schema(as = RunnerConfigsDeleteResponse)] pub struct DeleteResponse {} +#[tracing::instrument(skip_all)] pub async fn delete(ctx: ApiCtx, path: DeletePath, query: DeleteQuery) -> Result { let namespace = ctx .op(namespace::ops::resolve_for_name_global::Input { diff --git a/packages/core/api-peer/src/runners.rs b/packages/core/api-peer/src/runners.rs index 7501d622eb..2adbbee834 100644 --- a/packages/core/api-peer/src/runners.rs +++ b/packages/core/api-peer/src/runners.rs @@ -13,6 +13,7 @@ use utoipa::{IntoParams, ToSchema}; (status = 200, body = ListResponse), ), )] +#[tracing::instrument(skip_all)] pub async fn list(ctx: ApiCtx, _path: (), query: ListQuery) -> Result { let namespace = ctx .op(namespace::ops::resolve_for_name_global::Input { @@ -76,6 +77,7 @@ pub struct ListNamesResponse { pub pagination: Pagination, } +#[tracing::instrument(skip_all)] pub async fn list_names( ctx: ApiCtx, _path: (), diff --git a/packages/core/api-public/src/actors/create.rs b/packages/core/api-public/src/actors/create.rs index 8f4da5dbc2..c459e0a61d 100644 --- a/packages/core/api-public/src/actors/create.rs +++ b/packages/core/api-public/src/actors/create.rs @@ -59,6 +59,7 @@ pub async fn create( } } +#[tracing::instrument(skip_all)] async fn create_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/actors/delete.rs b/packages/core/api-public/src/actors/delete.rs index 30fee5dc22..e289265dcb 100644 --- a/packages/core/api-public/src/actors/delete.rs +++ b/packages/core/api-public/src/actors/delete.rs @@ -49,6 +49,7 @@ pub struct DeleteResponse {} ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn delete( Extension(ctx): Extension, headers: HeaderMap, @@ -61,6 +62,7 @@ pub async fn delete( } } +#[tracing::instrument(skip_all)] async fn delete_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/actors/get_or_create.rs b/packages/core/api-public/src/actors/get_or_create.rs index 16d8c6394a..b88630065f 100644 --- a/packages/core/api-public/src/actors/get_or_create.rs +++ b/packages/core/api-public/src/actors/get_or_create.rs @@ -87,6 +87,7 @@ pub async fn get_or_create( } } +#[tracing::instrument(skip_all)] async fn get_or_create_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/actors/list_names.rs b/packages/core/api-public/src/actors/list_names.rs index 1d0a643b7e..37e8c0e73b 100644 --- a/packages/core/api-public/src/actors/list_names.rs +++ b/packages/core/api-public/src/actors/list_names.rs @@ -28,6 +28,7 @@ use crate::ctx::ApiCtx; ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn list_names( Extension(ctx): Extension, headers: HeaderMap, @@ -39,6 +40,7 @@ pub async fn list_names( } } +#[tracing::instrument(skip_all)] async fn list_names_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/actors/utils.rs b/packages/core/api-public/src/actors/utils.rs index f62b537af0..6d582aca37 100644 --- a/packages/core/api-public/src/actors/utils.rs +++ b/packages/core/api-public/src/actors/utils.rs @@ -9,6 +9,7 @@ use std::collections::HashMap; /// Helper function to fetch an actor by ID, automatically routing to the correct datacenter /// based on the actor ID's label. +#[tracing::instrument(skip_all)] pub async fn fetch_actor_by_id( ctx: &ApiCtx, headers: HeaderMap, @@ -55,6 +56,7 @@ pub async fn fetch_actor_by_id( /// Helper function to fetch multiple actors by their IDs, automatically routing to the correct datacenters /// based on each actor ID's label. This function batches requests by datacenter for efficiency. +#[tracing::instrument(skip_all)] pub async fn fetch_actors_by_ids( ctx: &ApiCtx, headers: HeaderMap, @@ -186,6 +188,7 @@ pub fn extract_duplicate_key_error(err: &anyhow::Error) -> Option { } /// Determine the datacenter label to create the actor in. +#[tracing::instrument(skip_all)] pub async fn find_dc_for_actor_creation( ctx: &ApiCtx, namespace_id: Id, diff --git a/packages/core/api-public/src/datacenters.rs b/packages/core/api-public/src/datacenters.rs index be5e07f750..ea1013353b 100644 --- a/packages/core/api-public/src/datacenters.rs +++ b/packages/core/api-public/src/datacenters.rs @@ -15,6 +15,7 @@ use crate::ctx::ApiCtx; ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn list(Extension(ctx): Extension) -> Response { match list_inner(ctx).await { Ok(response) => Json(response).into_response(), diff --git a/packages/core/api-public/src/health.rs b/packages/core/api-public/src/health.rs index c5c3a33279..bf6384aef6 100644 --- a/packages/core/api-public/src/health.rs +++ b/packages/core/api-public/src/health.rs @@ -47,6 +47,7 @@ pub struct HealthResponse { ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn fanout(Extension(ctx): Extension) -> impl IntoResponse { match fanout_inner(ctx).await { Ok(response) => Json(response).into_response(), @@ -126,6 +127,7 @@ async fn fanout_inner(ctx: ApiCtx) -> Result { }) } +#[tracing::instrument(skip_all)] async fn send_health_check( ctx: &ApiCtx, dc: &rivet_config::config::topology::Datacenter, diff --git a/packages/core/api-public/src/metadata.rs b/packages/core/api-public/src/metadata.rs index 21b363500d..253e12b2ac 100644 --- a/packages/core/api-public/src/metadata.rs +++ b/packages/core/api-public/src/metadata.rs @@ -3,6 +3,7 @@ use axum::response::IntoResponse; use serde_json::json; /// Returns metadata about the API including runtime and version +#[tracing::instrument(skip_all)] pub async fn get_metadata() -> impl IntoResponse { Json(json!({ "runtime": "engine", diff --git a/packages/core/api-public/src/namespaces.rs b/packages/core/api-public/src/namespaces.rs index a5b5f66353..895e7f481c 100644 --- a/packages/core/api-public/src/namespaces.rs +++ b/packages/core/api-public/src/namespaces.rs @@ -23,6 +23,7 @@ use crate::ctx::ApiCtx; ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn list( Extension(ctx): Extension, headers: HeaderMap, @@ -64,6 +65,7 @@ async fn list_inner(ctx: ApiCtx, headers: HeaderMap, query: ListQuery) -> Result ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn create( Extension(ctx): Extension, headers: HeaderMap, @@ -75,6 +77,7 @@ pub async fn create( } } +#[tracing::instrument(skip_all)] async fn create_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/router.rs b/packages/core/api-public/src/router.rs index ad8665c57f..dee499f29f 100644 --- a/packages/core/api-public/src/router.rs +++ b/packages/core/api-public/src/router.rs @@ -38,6 +38,7 @@ use crate::{actors, ctx, datacenters, health, metadata, namespaces, runner_confi )] pub struct ApiDoc; +#[tracing::instrument(skip_all)] pub async fn router( name: &'static str, config: rivet_config::Config, @@ -114,6 +115,7 @@ pub async fn router( /// Middleware to wrap ApiCtx with auth handling capabilities and to throw an error if auth was not explicitly // handled in an endpoint +#[tracing::instrument(skip_all)] async fn auth_middleware( headers: HeaderMap, mut req: Request, diff --git a/packages/core/api-public/src/runner_configs/delete.rs b/packages/core/api-public/src/runner_configs/delete.rs index faaa45ea5e..b4d604e63c 100644 --- a/packages/core/api-public/src/runner_configs/delete.rs +++ b/packages/core/api-public/src/runner_configs/delete.rs @@ -25,6 +25,7 @@ use crate::ctx::ApiCtx; ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn delete( Extension(ctx): Extension, headers: HeaderMap, @@ -37,6 +38,7 @@ pub async fn delete( } } +#[tracing::instrument(skip_all)] async fn delete_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/runner_configs/list.rs b/packages/core/api-public/src/runner_configs/list.rs index 8a62446185..90f284fca8 100644 --- a/packages/core/api-public/src/runner_configs/list.rs +++ b/packages/core/api-public/src/runner_configs/list.rs @@ -42,6 +42,7 @@ pub struct RunnerConfigDatacenters { ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn list( Extension(ctx): Extension, headers: HeaderMap, @@ -54,6 +55,7 @@ pub async fn list( } } +#[tracing::instrument(skip_all)] async fn list_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/runner_configs/refresh_metadata.rs b/packages/core/api-public/src/runner_configs/refresh_metadata.rs index c6872b38e0..b6d2c14036 100644 --- a/packages/core/api-public/src/runner_configs/refresh_metadata.rs +++ b/packages/core/api-public/src/runner_configs/refresh_metadata.rs @@ -48,6 +48,7 @@ pub struct RefreshMetadataResponse {} ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn refresh_metadata( Extension(ctx): Extension, Path(path): Path, @@ -60,6 +61,7 @@ pub async fn refresh_metadata( } } +#[tracing::instrument(skip_all)] async fn refresh_metadata_inner( ctx: ApiCtx, path: RefreshMetadataPath, diff --git a/packages/core/api-public/src/runner_configs/serverless_health_check.rs b/packages/core/api-public/src/runner_configs/serverless_health_check.rs index ab593a55e9..eba5557ec2 100644 --- a/packages/core/api-public/src/runner_configs/serverless_health_check.rs +++ b/packages/core/api-public/src/runner_configs/serverless_health_check.rs @@ -51,6 +51,7 @@ pub enum ServerlessHealthCheckResponse { ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn serverless_health_check( Extension(ctx): Extension, Query(query): Query, diff --git a/packages/core/api-public/src/runner_configs/upsert.rs b/packages/core/api-public/src/runner_configs/upsert.rs index 0509a3c5ce..7cff66a6ca 100644 --- a/packages/core/api-public/src/runner_configs/upsert.rs +++ b/packages/core/api-public/src/runner_configs/upsert.rs @@ -38,6 +38,7 @@ pub struct UpsertRequest { ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn upsert( Extension(ctx): Extension, headers: HeaderMap, @@ -51,6 +52,7 @@ pub async fn upsert( } } +#[tracing::instrument(skip_all)] async fn upsert_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/runner_configs/utils.rs b/packages/core/api-public/src/runner_configs/utils.rs index 7ccfcfd100..138890cf94 100644 --- a/packages/core/api-public/src/runner_configs/utils.rs +++ b/packages/core/api-public/src/runner_configs/utils.rs @@ -50,6 +50,7 @@ fn truncate_response_body(body: &str) -> String { /// Fetches metadata from a serverless runner at the given URL. /// /// Returns metadata including runtime, version, and actor names if available. +#[tracing::instrument(skip_all)] pub async fn fetch_serverless_runner_metadata( url: String, headers: HashMap, @@ -144,6 +145,7 @@ pub async fn fetch_serverless_runner_metadata( } /// Fetches metadata from the given URL and populates actor names in the database. +#[tracing::instrument(skip_all)] pub async fn refresh_runner_config_metadata( ctx: ApiCtx, namespace_id: Id, diff --git a/packages/core/api-public/src/runners.rs b/packages/core/api-public/src/runners.rs index 0c91a1ff55..c03dbd6cc1 100644 --- a/packages/core/api-public/src/runners.rs +++ b/packages/core/api-public/src/runners.rs @@ -24,6 +24,7 @@ use crate::ctx::ApiCtx; ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn list( Extension(ctx): Extension, headers: HeaderMap, @@ -97,6 +98,7 @@ pub struct ListNamesResponse { ), security(("bearer_auth" = [])), )] +#[tracing::instrument(skip_all)] pub async fn list_names( Extension(ctx): Extension, headers: HeaderMap, @@ -108,6 +110,7 @@ pub async fn list_names( } } +#[tracing::instrument(skip_all)] async fn list_names_inner( ctx: ApiCtx, headers: HeaderMap, diff --git a/packages/core/api-public/src/ui.rs b/packages/core/api-public/src/ui.rs index 22698cbdb6..e638ffe50e 100644 --- a/packages/core/api-public/src/ui.rs +++ b/packages/core/api-public/src/ui.rs @@ -7,6 +7,7 @@ use rivet_api_builder::extract::Path; static UI_DIR: Dir<'_> = include_dir!("$OUT_DIR/ui"); +#[tracing::instrument(skip_all)] pub async fn serve_index() -> Response { if let Some(index_file) = UI_DIR.get_file("index.html") { ([(header::CONTENT_TYPE, "text/html")], index_file.contents()).into_response() @@ -15,6 +16,7 @@ pub async fn serve_index() -> Response { } } +#[tracing::instrument(skip_all)] pub async fn serve_ui(Path(path): Path) -> Response { let file_path = path.trim_start_matches('/');