Skip to content

Commit

Permalink
feat(monitors): Add trace context to CheckIns (#2241)
Browse files Browse the repository at this point in the history
Adds `contexts` to the CheckIn payload in order to enable tracing.
  • Loading branch information
rjo100 committed Jun 23, 2023
1 parent e13d231 commit 28c0f19
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add filter based on transaction names. ([#2118](https://github.com/getsentry/relay/pull/2118))
- 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

0 comments on commit 28c0f19

Please sign in to comment.