From 95c3780291241fa6de8d2c0ae9bb09d3ce42d18d Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Wed, 4 Dec 2024 10:58:58 +0100 Subject: [PATCH] Move up creation of Rack instrumentation event (#1339) We see a small difference between the transaction duration and the total duration of child span groups. Move up the transaction's Rack event creation so it happens directly after the transaction is created to minimize this difference. Context: https://appsignal.slack.com/archives/C7XHXQ7N0/p1733142713081549?thread_ts=1733126790.603229&cid=C7XHXQ7N0 --- .changesets/reduce-rack-transaction-event-creation.md | 6 ++++++ lib/appsignal/rack/event_handler.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changesets/reduce-rack-transaction-event-creation.md diff --git a/.changesets/reduce-rack-transaction-event-creation.md b/.changesets/reduce-rack-transaction-event-creation.md new file mode 100644 index 000000000..c62366f9e --- /dev/null +++ b/.changesets/reduce-rack-transaction-event-creation.md @@ -0,0 +1,6 @@ +--- +bump: patch +type: change +--- + +Minimize difference between Rack transaction duration and total child event durations. diff --git a/lib/appsignal/rack/event_handler.rb b/lib/appsignal/rack/event_handler.rb index 4203d07ab..b2f22feef 100644 --- a/lib/appsignal/rack/event_handler.rb +++ b/lib/appsignal/rack/event_handler.rb @@ -59,6 +59,7 @@ def on_start(request, _response) return unless request_handler?(request.env[APPSIGNAL_EVENT_HANDLER_ID]) transaction = Appsignal::Transaction.create(Appsignal::Transaction::HTTP_REQUEST) + transaction.start_event request.env[APPSIGNAL_TRANSACTION] = transaction request.env[RACK_AFTER_REPLY] ||= [] @@ -83,7 +84,6 @@ def on_start(request, _response) # One such scenario is when a Puma "lowlevel_error" occurs. Appsignal::Transaction.complete_current! end - transaction.start_event end end