Skip to content

Commit

Permalink
feat(monitors): Pass SENTRY_TRACE_ID down execution path (#1441)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com>
  • Loading branch information
evanpurkhiser and kamilogorek committed Jan 30, 2023
1 parent 5b2f5c2 commit de0895c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/commands/monitors/run.rs
@@ -1,5 +1,5 @@
use std::process;
use std::time::Instant;
use std::{env, process};

use anyhow::Result;
use clap::{Arg, ArgMatches, Command};
Expand Down Expand Up @@ -58,6 +58,11 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
p.args(&args[1..]);
p.env("SENTRY_MONITOR_ID", monitor.to_string());

// Inherit outer SENTRY_TRACE_ID if present
let trace_id = env::var_os("SENTRY_TRACE_ID")
.unwrap_or_else(|| Uuid::new_v4().simple().to_string().into());
p.env("SENTRY_TRACE_ID", trace_id);

let (success, code) = match p.status() {
Ok(status) => (status.success(), status.code()),
Err(err) => {
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/_cases/monitors/monitors-run-env.trycmd
@@ -1,6 +1,7 @@
```
$ sentry-cli monitors run 85a34e5a-c0b6-11ec-9d64-0242ac120002 -- sh -c 'env | grep SENTRY_MONITOR_ID'
$ sentry-cli monitors run 85a34e5a-c0b6-11ec-9d64-0242ac120002 -- sh -c 'env | sort | grep -E "SENTRY_MONITOR_ID|SENTRY_TRACE_ID"'
? success
SENTRY_MONITOR_ID=85a34e5a-c0b6-11ec-9d64-0242ac120002
SENTRY_TRACE_ID=[..]

```

0 comments on commit de0895c

Please sign in to comment.