Skip to content

Include user context in a newly built Error#1644

Open
aleksandrs-ledovskis wants to merge 1 commit into
elastic:mainfrom
aleksandrs-ledovskis:fix/error-inherits-transaction-user
Open

Include user context in a newly built Error#1644
aleksandrs-ledovskis wants to merge 1 commit into
elastic:mainfrom
aleksandrs-ledovskis:fix/error-inherits-transaction-user

Conversation

@aleksandrs-ledovskis

@aleksandrs-ledovskis aleksandrs-ledovskis commented Jun 22, 2026

Copy link
Copy Markdown

What does this pull request do?

Captured errors now inherit the ElasticAPM::Context::User of the active transaction.

ErrorBuilder#add_current_transaction_fields already copies the transaction's labels and custom context onto each error, but silently omitted user - so errors reported during an authenticated request arrived with no user, even though the transaction (set via ElasticAPM.set_user) had one.

An explicitly-set error user takes precedence; otherwise the transaction's user is inherited. This aligns the Ruby agent with the Node.js' (1, 2), and Python's (1, 2) Elastic APM agents - all attaching the transaction's user to captured errors.

From my understanding of "apm-agent-ruby" it's an regression hailing from year 2019.

The original implementation via #35

error.context = transaction.context.dup

did add the user to Error's context, but it was subsequently lost in #335 with note

only copying over relevant data such as tags and custom.

Per included spec (which had no matcher part for error's user)

ElasticAPM.set_user(Struct.new(:id).new(321))

it is clear that intent was not to drop user linkage.

Why is it important?

Lacking a user's information the error metadata is less valuable. Cross-referencing with a specific set of circumstances is harder and more time consuming.

Checklist

  • I have signed the Contributor License Agreement.
  • My code follows the style guidelines of this project (See .rubocop.yml)
  • I have rebased my changes on top of the latest main branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related issues

@aleksandrs-ledovskis aleksandrs-ledovskis force-pushed the fix/error-inherits-transaction-user branch from 0964a6a to c865966 Compare July 11, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant