From dfe8792c2c8ae651f23548dded29af852ee7559e Mon Sep 17 00:00:00 2001 From: Benjamin Curtis Date: Tue, 22 Oct 2024 05:03:26 -0700 Subject: [PATCH] Add request_id to notices Foe #616 --- lib/honeybadger/agent.rb | 1 + lib/honeybadger/notice.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/honeybadger/agent.rb b/lib/honeybadger/agent.rb index acc12744..a930cc7a 100644 --- a/lib/honeybadger/agent.rb +++ b/lib/honeybadger/agent.rb @@ -149,6 +149,7 @@ def notify(exception_or_opts = nil, opts = {}, **kwargs) opts[:rack_env] ||= context_manager.get_rack_env opts[:global_context] ||= context_manager.get_context opts[:breadcrumbs] ||= breadcrumbs.dup + opts[:request_id] ||= context_manager.get_request_id notice = Notice.new(config, opts) diff --git a/lib/honeybadger/notice.rb b/lib/honeybadger/notice.rb index c9675463..705a51da 100644 --- a/lib/honeybadger/notice.rb +++ b/lib/honeybadger/notice.rb @@ -144,6 +144,9 @@ def tags=(tags) # Custom details data attr_accessor :details + # The ID of the request which caused this notice. + attr_accessor :request_id + # The parsed exception backtrace. Lines in this backtrace that are from installed gems # have the base path for gem installs replaced by "[GEM_ROOT]", while those in the project # have "[PROJECT_ROOT]". @@ -213,13 +216,7 @@ def initialize(config, opts = {}) self.api_key = opts[:api_key] || config[:api_key] self.tags = construct_tags(opts[:tags]) | construct_tags(context[:tags]) - self.url = opts[:url] || request_hash[:url] || nil - self.action = opts[:action] || request_hash[:action] || nil - self.component = opts[:controller] || opts[:component] || request_hash[:component] || nil - self.params = opts[:parameters] || opts[:params] || request_hash[:params] || {} - self.session = opts[:session] || request_hash[:session] || {} - self.cgi_data = opts[:cgi_data] || request_hash[:cgi_data] || {} - self.details = opts[:details] || {} + self.request_id = opts[:request_id] || nil self.session = opts[:session][:data] if opts[:session] && opts[:session][:data] @@ -261,6 +258,9 @@ def as_json(*args) stats: stats, time: now, pid: pid + }, + correlation_context: { + request_id: s(request_id) } } end