Skip to content
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

feat(monitors): Add trace context to CheckIns #2241

Merged
merged 15 commits into from
Jun 23, 2023
1 change: 1 addition & 0 deletions py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Add `lock` attribute to the frame protocol. ([#2171](https://github.com/getsentry/relay/pull/2171))
- Add trace context to CheckIns. ([#2241](https://github.com/getsentry/relay/pull/2241))

## 0.8.25

Expand Down
30 changes: 28 additions & 2 deletions relay-monitors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum IntervalName {
Minute,
}

/// The monitor configuration playload for upserting monitors during check-in
/// The monitor configuration payload for upserting monitors during check-in
#[derive(Debug, Deserialize, Serialize)]
pub struct MonitorConfig {
/// The monitor schedule configuration
Expand All @@ -98,6 +98,22 @@ pub struct MonitorConfig {
timezone: Option<String>,
}

/// The trace context sent with a check-in.
#[derive(Debug, Deserialize, Serialize)]
pub struct CheckInTrace {
/// Trace-ID of the check-in.
#[serde(serialize_with = "uuid_simple")]
trace_id: Uuid,
}

/// Any contexts sent in the check-in payload.
#[derive(Debug, Deserialize, Serialize)]
pub struct CheckInContexts {
/// Trace context sent with a check-in.
#[serde(default, skip_serializing_if = "Option::is_none")]
trace: Option<CheckInTrace>,
}

/// The monitor check-in payload.
#[derive(Debug, Deserialize, Serialize)]
pub struct CheckIn {
Expand All @@ -122,6 +138,11 @@ pub struct CheckIn {
/// monitor configuration to support upserts.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub monitor_config: Option<MonitorConfig>,

/// Contexts describing the associated environment of the job run.
/// Only supports trace for now.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub contexts: Option<CheckInContexts>,
}

/// Normalizes a monitor check-in payload.
Expand Down Expand Up @@ -172,7 +193,12 @@ mod tests {
"monitor_slug": "my-monitor",
"status": "in_progress",
"environment": "production",
"duration": 21.0
"duration": 21.0,
"contexts": {
"trace": {
"trace_id": "8f431b7aa08441bbbd5a0100fd91f9fe"
}
}
}"#;

let check_in = serde_json::from_str::<CheckIn>(json).unwrap();
Expand Down
1 change: 1 addition & 0 deletions relay-server/src/endpoints/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl CronParams {
environment: query.environment,
duration: query.duration,
monitor_config: None,
contexts: None,
})
.map_err(BadStoreRequest::InvalidJson)?,
);
Expand Down