The basic use case we wanted to solve was to add a request_id in an Airbrake report. This makes the most sense in the session field for the report. We also realized that we're storing the request_id in the Logger metadata, and we're storing a lot of useful information in the Logger metadata. Let's face it: if it's in the Logger metadata, it's good for debugging. So it seems natural to also include it in an Airbrake report.
Adding Logger metadata to the session is optional. You need to set session: :include_logger_metadata in the :airbrake_client config.
All values from Logger.metadata() are added to the session field. The map for :session in the opts passed to a report/? function overrides the Logger metadata.
Testing
I used this code to manually test:
defmodule ReportTest do
def send do
Logger.metadata(foo: 5, bar: "yes!")
Airbrake.report(
[type: "AirbrakeClientTester", message: "testing Airbrake.report/2 with maximal options"],
context: %{foo: 5},
params: %{foo: 55},
session: %{foo: 555},
env: %{foo: 5555}
) |> IO.inspect()
end
end
ReportTest.send()
Ran it like this: mix compile && iex -S mix run manual_test.exs
Description
The basic use case we wanted to solve was to add a
request_id
in an Airbrake report. This makes the most sense in thesession
field for the report. We also realized that we're storing therequest_id
in the Logger metadata, and we're storing a lot of useful information in the Logger metadata. Let's face it: if it's in the Logger metadata, it's good for debugging. So it seems natural to also include it in an Airbrake report.Adding Logger metadata to the session is optional. You need to set
session: :include_logger_metadata
in the:airbrake_client
config.All values from
Logger.metadata()
are added to thesession
field. The map for:session
in theopts
passed to areport/?
function overrides the Logger metadata.Testing
I used this code to manually test:
Ran it like this:
mix compile && iex -S mix run manual_test.exs
Screenshots: