Skip to content

Commit f81fe30

Browse files
gautamg795Convex, Inc.
authored andcommitted
set some sentry tags when running in Nomad (#43763)
GitOrigin-RevId: 2b8019950f25603235529a046c8157b08676dcaa
1 parent a8c60ef commit f81fe30

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

crates/common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub mod query_journal;
6363
pub mod retriable_stream;
6464
pub mod runtime;
6565
pub mod schemas;
66+
pub mod sentry;
6667
pub mod sha256;
6768
pub mod shapes;
6869
pub mod shutdown;

crates/common/src/sentry.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use sentry::Scope;
2+
3+
pub fn set_sentry_tags(scope: &mut Scope) {
4+
if let Ok(alloc_id) = std::env::var("NOMAD_ALLOC_ID") {
5+
scope.set_tag("nomad_alloc_id", alloc_id);
6+
}
7+
if let Ok(job_name) = std::env::var("NOMAD_JOB_NAME") {
8+
scope.set_tag("nomad_job_name", job_name);
9+
}
10+
if let Ok(group_name) = std::env::var("NOMAD_GROUP_NAME") {
11+
scope.set_tag("nomad_group_name", group_name);
12+
}
13+
if let Ok(task_name) = std::env::var("NOMAD_TASK_NAME") {
14+
scope.set_tag("nomad_task_name", task_name);
15+
}
16+
if let Ok(dc) = std::env::var("NOMAD_DC") {
17+
scope.set_tag("nomad_dc", dc);
18+
}
19+
}

crates/load_generator/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use common::{
5151
HttpResponseError,
5252
NoopRouteMapper,
5353
},
54+
sentry::set_sentry_tags,
5455
};
5556
use event_receiver::Event;
5657
use futures::{
@@ -440,6 +441,9 @@ fn main() -> Result<(), MainError> {
440441
});
441442
if sentry.is_enabled() {
442443
tracing::info!("Sentry is enabled! Check the load-generator project for errors: https://sentry.io/organizations/convex-dev/projects/load-generator/?project=6505624");
444+
sentry::configure_scope(|scope| {
445+
set_sentry_tags(scope);
446+
});
443447
} else {
444448
tracing::info!("Sentry is not enabled.")
445449
}

crates/local_backend/src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use common::{
66
errors::MainError,
77
http::ConvexHttpService,
88
runtime::Runtime,
9+
sentry::set_sentry_tags,
910
shutdown::ShutdownSignal,
1011
version::SERVER_VERSION_STR,
1112
};
@@ -60,14 +61,15 @@ fn main() -> Result<(), MainError> {
6061
.map(|dsn| dsn.project_id().to_string())
6162
.unwrap_or("unknown".to_string())
6263
);
63-
if let Some(sentry_identifier) = config.sentry_identifier.clone() {
64-
sentry::configure_scope(|scope| {
64+
sentry::configure_scope(|scope| {
65+
if let Some(sentry_identifier) = config.sentry_identifier.clone() {
6566
scope.set_user(Some(sentry::User {
6667
id: Some(sentry_identifier),
6768
..Default::default()
6869
}));
69-
});
70-
}
70+
}
71+
set_sentry_tags(scope);
72+
});
7173
} else {
7274
tracing::info!("Sentry is not enabled.")
7375
}

0 commit comments

Comments
 (0)