Skip to content

Commit c59fd4e

Browse files
committed
feat(gateway): add more tracing events
1 parent 3445eda commit c59fd4e

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

gateway/src/api/latest.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use shuttle_common::models::error::ErrorKind;
2020
use shuttle_common::models::{project, user};
2121
use tokio::sync::mpsc::Sender;
2222
use tower_http::trace::TraceLayer;
23-
use tracing::{debug, debug_span, field, Span};
23+
use tracing::{debug, debug_span, field, instrument, Span};
2424

2525
use crate::acme::{AcmeClient, CustomDomain};
2626
use crate::auth::{Admin, ScopedUser, User};
@@ -65,6 +65,7 @@ impl StatusResponse {
6565
}
6666
}
6767

68+
#[instrument(skip_all, fields(%account_name))]
6869
async fn get_user(
6970
State(RouterState { service, .. }): State<RouterState>,
7071
Path(account_name): Path<AccountName>,
@@ -75,6 +76,7 @@ async fn get_user(
7576
Ok(AxumJson(user.into()))
7677
}
7778

79+
#[instrument(skip_all, fields(%account_name))]
7880
async fn post_user(
7981
State(RouterState { service, .. }): State<RouterState>,
8082
Path(account_name): Path<AccountName>,
@@ -85,6 +87,7 @@ async fn post_user(
8587
Ok(AxumJson(user.into()))
8688
}
8789

90+
#[instrument(skip(service))]
8891
async fn get_project(
8992
State(RouterState { service, .. }): State<RouterState>,
9093
ScopedUser { scope, .. }: ScopedUser,
@@ -98,6 +101,7 @@ async fn get_project(
98101
Ok(AxumJson(response))
99102
}
100103

104+
#[instrument(skip_all, fields(%project))]
101105
async fn post_project(
102106
State(RouterState { service, sender }): State<RouterState>,
103107
User { name, .. }: User,
@@ -121,6 +125,7 @@ async fn post_project(
121125
Ok(AxumJson(response))
122126
}
123127

128+
#[instrument(skip_all, fields(%project))]
124129
async fn delete_project(
125130
State(RouterState { service, sender }): State<RouterState>,
126131
ScopedUser { scope: project, .. }: ScopedUser,
@@ -149,6 +154,7 @@ async fn delete_project(
149154
Ok(AxumJson(response))
150155
}
151156

157+
#[instrument(skip_all, fields(scope = %scoped_user.scope))]
152158
async fn route_project(
153159
State(RouterState { service, .. }): State<RouterState>,
154160
scoped_user: ScopedUser,
@@ -176,6 +182,7 @@ async fn get_status(State(RouterState { sender, .. }): State<RouterState>) -> Re
176182
.unwrap()
177183
}
178184

185+
#[instrument(skip_all)]
179186
async fn revive_projects(
180187
_: Admin,
181188
State(RouterState { service, sender }): State<RouterState>,
@@ -185,6 +192,7 @@ async fn revive_projects(
185192
.map_err(|_| Error::from_kind(ErrorKind::Internal))
186193
}
187194

195+
#[instrument(skip_all, fields(%email, ?acme_server))]
188196
async fn create_acme_account(
189197
_: Admin,
190198
Extension(acme_client): Extension<AcmeClient>,
@@ -196,6 +204,7 @@ async fn create_acme_account(
196204
Ok(AxumJson(res))
197205
}
198206

207+
#[instrument(skip_all, fields(%project_name, %fqdn))]
199208
async fn request_acme_certificate(
200209
_: Admin,
201210
State(RouterState { service, sender }): State<RouterState>,

gateway/src/main.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::io::{self, Cursor};
1919
use std::path::{Path, PathBuf};
2020
use std::sync::Arc;
2121
use std::time::Duration;
22-
use tracing::{debug, error, info, info_span, trace, warn};
22+
use tracing::{debug, error, info, info_span, trace, warn, Instrument};
2323
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
2424

2525
#[tokio::main(flavor = "multi_thread")]
@@ -122,20 +122,24 @@ async fn start(db: SqlitePool, fs: PathBuf, args: StartArgs) -> io::Result<()> {
122122
"running health checks",
123123
healthcheck.num_projects = projects.len()
124124
);
125-
let _ = span.enter();
126-
for (project_name, _) in projects {
127-
if let Ok(handle) = gateway
128-
.new_task()
129-
.project(project_name)
130-
.and_then(task::check_health())
131-
.send(&sender)
132-
.await
133-
{
134-
// we wait for the check to be done before
135-
// queuing up the next one
136-
handle.await
125+
126+
async move {
127+
for (project_name, _) in projects {
128+
if let Ok(handle) = gateway
129+
.new_task()
130+
.project(project_name)
131+
.and_then(task::check_health())
132+
.send(&sender)
133+
.await
134+
{
135+
// we wait for the check to be done before
136+
// queuing up the next one
137+
handle.await
138+
}
137139
}
138140
}
141+
.instrument(span)
142+
.await;
139143
}
140144
}
141145
}

gateway/src/project.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use once_cell::sync::Lazy;
1919
use rand::distributions::{Alphanumeric, DistString};
2020
use serde::{Deserialize, Serialize};
2121
use tokio::time::{self, timeout};
22-
use tracing::{debug, error};
22+
use tracing::{debug, error, instrument};
2323

2424
use crate::{
2525
ContainerSettings, DockerContext, EndState, Error, ErrorKind, IntoTryState, ProjectName,
@@ -276,6 +276,7 @@ where
276276
type Next = Self;
277277
type Error = Infallible;
278278

279+
#[instrument(skip_all, fields(state = %self.state()))]
279280
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
280281
let previous = self.clone();
281282
let previous_state = previous.state();
@@ -557,6 +558,7 @@ where
557558
type Next = ProjectStarting;
558559
type Error = ProjectError;
559560

561+
#[instrument(skip_all)]
560562
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
561563
let container_name = self.container_name(ctx);
562564
let container = ctx
@@ -593,6 +595,7 @@ where
593595
type Next = ProjectStarted;
594596
type Error = ProjectError;
595597

598+
#[instrument(skip_all)]
596599
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
597600
let container_id = self.container.id.as_ref().unwrap();
598601
ctx.docker()
@@ -642,6 +645,7 @@ where
642645
type Next = ProjectReadying;
643646
type Error = ProjectError;
644647

648+
#[instrument(skip_all)]
645649
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
646650
time::sleep(Duration::from_secs(1)).await;
647651

@@ -688,6 +692,7 @@ where
688692
type Next = Self;
689693
type Error = ProjectError;
690694

695+
#[instrument(skip_all)]
691696
async fn next(mut self, _ctx: &Ctx) -> Result<Self::Next, Self::Error> {
692697
Ok(self)
693698
}
@@ -781,6 +786,7 @@ where
781786

782787
type Error = ProjectError;
783788

789+
#[instrument(skip_all)]
784790
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
785791
let Self { container } = self;
786792
ctx.docker()
@@ -808,6 +814,7 @@ where
808814
type Next = ProjectStarting;
809815
type Error = ProjectError;
810816

817+
#[instrument(skip_all)]
811818
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
812819
let container = self.container;
813820

@@ -860,6 +867,7 @@ where
860867
type Next = ProjectDestroyed;
861868
type Error = ProjectError;
862869

870+
#[instrument(skip_all)]
863871
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
864872
let container_id = self.container.id.as_ref().unwrap();
865873
ctx.docker()
@@ -895,6 +903,7 @@ where
895903
type Next = ProjectDestroyed;
896904
type Error = ProjectError;
897905

906+
#[instrument(skip_all)]
898907
async fn next(self, _ctx: &Ctx) -> Result<Self::Next, Self::Error> {
899908
Ok(self)
900909
}
@@ -980,6 +989,7 @@ where
980989
type Next = Self;
981990
type Error = Infallible;
982991

992+
#[instrument(skip_all)]
983993
async fn next(self, _ctx: &Ctx) -> Result<Self::Next, Self::Error> {
984994
Ok(self)
985995
}

0 commit comments

Comments
 (0)