Skip to content

Commit 6b61b31

Browse files
authored
fix: send trace origin correctly (#906)
1 parent 75a8c03 commit 6b61b31

File tree

8 files changed

+20
-8
lines changed

8 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- Previously, if a middleware were to process the request after the Sentry middleware and return an error, our middleware would always capture it and send it to Sentry, regardless if it was a client, server or some other kind of error.
1818
- With this change, we capture errors returned by middleware only if those errors can be classified as server errors.
1919
- There is no change in behavior when it comes to errors returned by services, in which case the Sentry middleware only captures server errors exclusively.
20+
- fix: send trace origin correctly ([#906](https://github.com/getsentry/sentry-rust/pull/906)) by @lcian
21+
- `TraceContext` now has an additional field `origin`, used to report which integration created a transaction.
2022

2123
### Behavioral changes
2224

sentry-actix/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ where
322322

323323
let transaction = hub.start_transaction(ctx);
324324
transaction.set_request(sentry_req.clone());
325-
transaction.set_data("origin", "auto.http.actix".into());
325+
transaction.set_origin("auto.http.actix");
326326
Some(transaction)
327327
} else {
328328
None

sentry-core/src/performance.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,12 @@ impl Transaction {
819819
}
820820
}
821821

822+
/// Sets the origin for this transaction, indicating what created it.
823+
pub fn set_origin(&self, origin: &str) {
824+
let mut inner = self.inner.lock().unwrap();
825+
inner.context.origin = Some(origin.to_owned());
826+
}
827+
822828
/// Returns the headers needed for distributed tracing.
823829
/// Use [`crate::Scope::iter_trace_propagation_headers`] to obtain the active
824830
/// trace's distributed tracing headers.

sentry-opentelemetry/src/processor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ impl SpanProcessor for SentrySpanProcessor {
174174
// TODO: read OTEL semantic convention span attributes and map them to the appropriate
175175
// Sentry span attributes/context values
176176

177-
if matches!(sentry_span, TransactionOrSpan::Transaction(_)) {
178-
sentry_span.set_data("origin", "auto.otel".into())
177+
if let TransactionOrSpan::Transaction(transaction) = &sentry_span {
178+
transaction.set_origin("auto.otel");
179179
}
180180
sentry_span.set_status(convert_span_status(&data.status));
181181
sentry_span.finish_with_timestamp(data.end_time);

sentry-tower/src/http.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ where
118118
if let Some((sentry_req, trx_ctx)) = slf.on_first_poll.take() {
119119
sentry_core::configure_scope(|scope| {
120120
if let Some(trx_ctx) = trx_ctx {
121-
let transaction: sentry_core::TransactionOrSpan =
122-
sentry_core::start_transaction(trx_ctx).into();
121+
let transaction = sentry_core::start_transaction(trx_ctx);
122+
transaction.set_origin("auto.http.tower");
123+
let transaction: sentry_core::TransactionOrSpan = transaction.into();
123124
transaction.set_request(sentry_req.clone());
124-
transaction.set_data("origin", "auto.http.tower".into());
125125
let parent_span = scope.get_span();
126126
scope.set_span(Some(transaction.clone()));
127127
*slf.transaction = Some((transaction, parent_span));

sentry-tracing/src/layer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ where
322322
};
323323

324324
let tx = sentry_core::start_transaction(ctx);
325-
tx.set_data("origin", "auto.tracing".into());
325+
tx.set_origin("auto.tracing");
326326
tx.into()
327327
}
328328
};

sentry-tracing/tests/smoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn should_instrument_function_with_event() {
3434
};
3535
assert_eq!(transaction.name, Some("function_with_tags".into()));
3636
assert_eq!(transaction.tags.len(), 1);
37-
assert_eq!(trace.data.len(), 7);
37+
assert_eq!(trace.data.len(), 6);
3838

3939
let tag = transaction
4040
.tags

sentry-types/src/protocol/v7.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,10 @@ pub struct TraceContext {
15041504
/// Describes the status of the span (e.g. `ok`, `cancelled`, etc.)
15051505
#[serde(default, skip_serializing_if = "Option::is_none")]
15061506
pub status: Option<SpanStatus>,
1507+
/// Describes what created the transaction. See the [develop
1508+
/// docs](https://develop.sentry.dev/sdk/telemetry/traces/trace-origin/) for more information.
1509+
#[serde(default, skip_serializing_if = "Option::is_none")]
1510+
pub origin: Option<String>,
15071511
/// Optional data attributes to be associated with the transaction.
15081512
#[serde(default, skip_serializing_if = "Map::is_empty")]
15091513
pub data: Map<String, Value>,

0 commit comments

Comments
 (0)