Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/elastic_apm/error_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def add_current_transaction_fields(error, transaction)

Util.reverse_merge!(error.context.labels, transaction.context.labels)
Util.reverse_merge!(error.context.custom, transaction.context.custom)
error.context.user = transaction.context.user if error.context.user.empty?
end
end
end
17 changes: 17 additions & 0 deletions spec/elastic_apm/error_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module ElasticAPM
expect(error.exception.message).to eq 'divided by 0'
expect(error.exception.type).to eq 'ZeroDivisionError'
expect(error.exception.handled).to be true
expect(error.context.user).to be_empty
end

it 'sets properties from current transaction', :intercept do
Expand Down Expand Up @@ -67,6 +68,22 @@ module ElasticAPM
expect(error.context.labels).to match(my_tag: '123', more: 'totes')
expect(error.context.custom)
.to match(all_the_other_things: 'blah blah')
expect(error.context.user)
.to have_attributes(id: '321', email: nil, username: nil)
end

it 'keeps an explicit error user over the transaction user', :intercept do
with_agent do
ElasticAPM.with_transaction('t') do
ElasticAPM.set_user(Struct.new(:id).new('txn-user'))

context = Context.new(user: Context::User.new(id: 'error-user'))
ElasticAPM.report(actual_exception, context: context)
end
end

error = @intercepted.errors.last
expect(error.context.user).to have_attributes(id: 'error-user')
end
end

Expand Down
Loading