Skip to content

Commit

Permalink
tower: Use tx.set_request() to set HTTP request metadata
Browse files Browse the repository at this point in the history
Without this the transaction does not have any HTTP request metadata attached, because apparently the event processor is not running for performance traces.

Note that I had to reorder the contents of the `configure_scope()` callback to be able to access `sentry_req` before it disappears into the `add_event_processor()` callback.
  • Loading branch information
Turbo87 committed Apr 25, 2023
1 parent cf7d956 commit bfc54c6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sentry-tower/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,21 @@ where
let slf = self.project();
if let Some((sentry_req, trx_ctx)) = slf.on_first_poll.take() {
sentry_core::configure_scope(|scope| {
scope.add_event_processor(move |mut event| {
if event.request.is_none() {
event.request = Some(sentry_req.clone());
}
Some(event)
});

if let Some(trx_ctx) = trx_ctx {
let transaction: sentry_core::TransactionOrSpan =
sentry_core::start_transaction(trx_ctx).into();
transaction.set_request(sentry_req.clone());
let parent_span = scope.get_span();
scope.set_span(Some(transaction.clone()));
*slf.transaction = Some((transaction, parent_span));
}

scope.add_event_processor(move |mut event| {
if event.request.is_none() {
event.request = Some(sentry_req);
}
Some(event)
});
});
}
match slf.future.poll(cx) {
Expand Down

0 comments on commit bfc54c6

Please sign in to comment.