Skip to content

Commit 08a5447

Browse files
authored
chore(api-public): add tracing to all handlers (#3199)
1 parent b32e06b commit 08a5447

29 files changed

+59
-1
lines changed

packages/common/api-util/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use anyhow::{Context, Result};
22
use axum::{body::Body, response::Response};
33
use futures_util::StreamExt;
44
use rivet_api_builder::{ApiCtx, ErrorResponse, RawErrorResponse};
5-
use serde::{Serialize, de::DeserializeOwned};
5+
use serde::{de::DeserializeOwned, Serialize};
66
use std::future::Future;
77

88
mod errors;
99

1010
pub use axum::http::{HeaderMap, Method};
1111

1212
/// Generic function to make raw requests to remote datacenters by label (returns axum Response)
13+
#[tracing::instrument(skip(ctx, headers, query, body))]
1314
pub async fn request_remote_datacenter_raw(
1415
ctx: &ApiCtx,
1516
dc_label: u16,
@@ -32,6 +33,8 @@ pub async fn request_remote_datacenter_raw(
3233
url.set_query(Some(&serde_html_form::to_string(q)?));
3334
}
3435

36+
tracing::debug!(%method, %url, "sending raw request to remote datacenter");
37+
3538
let mut request = client.request(method, url).headers(headers);
3639

3740
if let Some(b) = body {
@@ -48,6 +51,7 @@ pub async fn request_remote_datacenter_raw(
4851
}
4952

5053
/// Generic function to make requests to a specific datacenter
54+
#[tracing::instrument(skip(config, headers, query, body))]
5155
pub async fn request_remote_datacenter<T>(
5256
config: &rivet_config::Config,
5357
dc_label: u16,
@@ -72,6 +76,8 @@ where
7276
url.set_query(Some(&serde_html_form::to_string(q)?));
7377
}
7478

79+
tracing::debug!(%method, %url, "sending request to remote datacenter");
80+
7581
let mut request = client.request(method, url).headers(headers);
7682

7783
if let Some(b) = body {
@@ -89,6 +95,7 @@ where
8995

9096
/// Generic function to fanout requests to all datacenters and aggregate results
9197
/// Returns aggregated results and errors only if all requests fail
98+
#[tracing::instrument(skip(ctx, headers, query, local_handler, aggregator))]
9299
pub async fn fanout_to_datacenters<I, Q, F, Fut, A, R>(
93100
ctx: ApiCtx,
94101
headers: HeaderMap,
@@ -164,6 +171,7 @@ where
164171
Ok(aggregated)
165172
}
166173

174+
#[tracing::instrument(skip_all)]
167175
pub async fn reqwest_to_axum_response(reqwest_response: reqwest::Response) -> Result<Response> {
168176
let status = reqwest_response.status();
169177
let headers = reqwest_response.headers().clone();
@@ -178,6 +186,7 @@ pub async fn reqwest_to_axum_response(reqwest_response: reqwest::Response) -> Re
178186
Ok(response)
179187
}
180188

189+
#[tracing::instrument(skip_all)]
181190
pub async fn parse_response<T: DeserializeOwned>(reqwest_response: reqwest::Response) -> Result<T> {
182191
let status = reqwest_response.status();
183192
let response_text = reqwest_response.text().await?;

packages/core/api-peer/src/actors/create.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use gas::prelude::*;
33
use rivet_api_builder::ApiCtx;
44
use rivet_api_types::actors::create::{CreateQuery, CreateRequest, CreateResponse};
55

6+
#[tracing::instrument(skip_all)]
67
pub async fn create(
78
ctx: ApiCtx,
89
_path: (),

packages/core/api-peer/src/actors/delete.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct DeletePath {
3434
(status = 200, body = DeleteResponse),
3535
),
3636
)]
37+
#[tracing::instrument(skip_all)]
3738
pub async fn delete(ctx: ApiCtx, path: DeletePath, query: DeleteQuery) -> Result<DeleteResponse> {
3839
// Get the actor first to verify it exists
3940
let actors_res = ctx

packages/core/api-peer/src/actors/list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rivet_api_types::{actors::list::*, pagination::Pagination};
1111
(status = 200, body = ListResponse),
1212
),
1313
)]
14+
#[tracing::instrument(skip_all)]
1415
pub async fn list(ctx: ApiCtx, _path: (), query: ListQuery) -> Result<ListResponse> {
1516
let key = query.key;
1617
let actor_ids = query.actor_ids.as_ref().map(|x| {

packages/core/api-peer/src/actors/list_names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rivet_types::actors::ActorName;
1212
(status = 200, body = ListNamesResponse),
1313
),
1414
)]
15+
#[tracing::instrument(skip_all)]
1516
pub async fn list_names(
1617
ctx: ApiCtx,
1718
_path: (),

packages/core/api-peer/src/internal.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct CachePurgeRequest {
1212
#[derive(Serialize)]
1313
pub struct CachePurgeResponse {}
1414

15+
#[tracing::instrument(skip_all)]
1516
pub async fn cache_purge(
1617
ctx: ApiCtx,
1718
_path: (),
@@ -30,6 +31,7 @@ pub async fn cache_purge(
3031
#[derive(Serialize)]
3132
pub struct BumpServerlessAutoscalerResponse {}
3233

34+
#[tracing::instrument(skip_all)]
3335
pub async fn bump_serverless_autoscaler(
3436
ctx: ApiCtx,
3537
_path: (),

packages/core/api-peer/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod runners;
1111

1212
pub use router::router as create_router;
1313

14+
#[tracing::instrument(skip_all)]
1415
pub async fn start(config: rivet_config::Config, pools: rivet_pools::Pools) -> Result<()> {
1516
let host = config.api_peer().host();
1617
let port = config.api_peer().port();

packages/core/api-peer/src/namespaces.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rivet_util::Id;
66
use serde::{Deserialize, Serialize};
77
use utoipa::ToSchema;
88

9+
#[tracing::instrument(skip_all)]
910
pub async fn list(ctx: ApiCtx, _path: (), query: ListQuery) -> Result<ListResponse> {
1011
let namespace_ids = query.namespace_ids.as_ref().map(|x| {
1112
x.split(',')
@@ -72,6 +73,7 @@ pub struct CreateResponse {
7273
pub namespace: rivet_types::namespaces::Namespace,
7374
}
7475

76+
#[tracing::instrument(skip_all)]
7577
pub async fn create(
7678
ctx: ApiCtx,
7779
_path: (),

packages/core/api-peer/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rivet_api_builder::{create_router, prelude::*};
22

33
use crate::{actors, internal, namespaces, runner_configs, runners};
44

5+
#[tracing::instrument(skip_all)]
56
pub async fn router(
67
name: &'static str,
78
config: rivet_config::Config,

packages/core/api-peer/src/runner_configs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rivet_types::keys::namespace::runner_config::RunnerConfigVariant;
66
use serde::{Deserialize, Serialize};
77
use utoipa::{IntoParams, ToSchema};
88

9+
#[tracing::instrument(skip_all)]
910
pub async fn list(ctx: ApiCtx, _path: ListPath, query: ListQuery) -> Result<ListResponse> {
1011
let namespace = ctx
1112
.op(namespace::ops::resolve_for_name_global::Input {
@@ -94,6 +95,7 @@ pub struct UpsertRequest(pub rivet_api_types::namespaces::runner_configs::Runner
9495
#[schema(as = RunnerConfigsUpsertResponse)]
9596
pub struct UpsertResponse {}
9697

98+
#[tracing::instrument(skip_all)]
9799
pub async fn upsert(
98100
ctx: ApiCtx,
99101
path: UpsertPath,
@@ -134,6 +136,7 @@ pub struct DeletePath {
134136
#[schema(as = RunnerConfigsDeleteResponse)]
135137
pub struct DeleteResponse {}
136138

139+
#[tracing::instrument(skip_all)]
137140
pub async fn delete(ctx: ApiCtx, path: DeletePath, query: DeleteQuery) -> Result<DeleteResponse> {
138141
let namespace = ctx
139142
.op(namespace::ops::resolve_for_name_global::Input {

0 commit comments

Comments
 (0)