-
Notifications
You must be signed in to change notification settings - Fork 114
feat: add telemetry via sentry #2865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||||||||
use schemars::JsonSchema; | ||||||||||||||||||
use serde::{Deserialize, Serialize}; | ||||||||||||||||||
|
||||||||||||||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] | ||||||||||||||||||
pub struct Telemetry { | ||||||||||||||||||
pub enabled: bool, | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
impl Default for Telemetry { | ||||||||||||||||||
fn default() -> Self { | ||||||||||||||||||
// NOTE: Telemetry is opt-out | ||||||||||||||||||
Telemetry { enabled: true } | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Privacy and Security Consideration: The current implementation makes telemetry opt-out rather than opt-in (
Suggested change
Spotted by Diamond |
||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "rivet-telemetry" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
rivet-config.workspace = true | ||
sentry.workspace = true | ||
serde_json.workspace = true | ||
uuid.workspace = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Telemetry | ||
|
||
Telemetry from rivet-engine is opt-out. Update your config to include: | ||
|
||
```json | ||
{ | ||
// ... | ||
"telemetry": { | ||
"enabled": false | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||
use uuid::Uuid; | ||||||
|
||||||
const SENTRY_URL: &str = "https://7602663e43cb9dee8c42d1e5e70293f8@o4504307129188352.ingest.us.sentry.io/4509962797252608"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Concern: The Sentry DSN URL contains an authentication token ( Recommendation: Move this sensitive credential to a secure configuration mechanism:
This follows security best practices for credential management and prevents potential misuse of the Sentry instance.
Suggested change
Spotted by Diamond |
||||||
|
||||||
// We use synchronous main for Sentry. Read more: https://docs.sentry.io/platforms/rust/#async-main-function | ||||||
pub fn init(config: &rivet_config::Config) -> Option<sentry::ClientInitGuard> { | ||||||
if !config.telemetry.enabled { | ||||||
return None; | ||||||
} | ||||||
|
||||||
let guard = sentry::init(( | ||||||
SENTRY_URL, | ||||||
sentry::ClientOptions { | ||||||
release: sentry::release_name!(), | ||||||
..Default::default() | ||||||
}, | ||||||
)); | ||||||
|
||||||
sentry::configure_scope(|scope| { | ||||||
if let Ok(db) = serde_json::to_string(config.database()) { | ||||||
scope.set_tag("database", db); | ||||||
} | ||||||
if let Ok(ps) = serde_json::to_string(config.pubsub()) { | ||||||
scope.set_tag("pubsub", ps); | ||||||
} | ||||||
if let Ok(cache) = serde_json::to_string(config.cache()) { | ||||||
scope.set_tag("cache", cache); | ||||||
} | ||||||
if let Ok(topo) = serde_json::to_string(config.topology()) { | ||||||
scope.set_tag("topology", topo); | ||||||
} | ||||||
}); | ||||||
|
||||||
Some(guard) | ||||||
} | ||||||
|
||||||
pub fn capture_error(err: &anyhow::Error) -> Uuid { | ||||||
sentry::integrations::anyhow::capture_anyhow(err) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a type inconsistency in how the status code is handled. On line 131,
status_code
is assigned to variablestatus
, but on line 148,status_code
is used directly when setting the Sentry tag.For proper Sentry tag serialization, consider using the string representation of the status code:
This ensures the status code is properly serialized as a string value when sent to Sentry, rather than potentially passing the StatusCode enum directly.
Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.