Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set session from Logger metadata #29

Merged
merged 10 commits into from
Apr 2, 2024
Merged

Conversation

jdfrens
Copy link
Contributor

@jdfrens jdfrens commented Apr 1, 2024

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 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

Screenshots:

Screenshot 2024-04-01 at 1 38 06 PM

Screenshot 2024-04-01 at 1 38 37 PM

@jdfrens jdfrens force-pushed the set-session-from-logger-metadata branch from 57d67fa to b64271f Compare April 1, 2024 18:48
backtrace: Backtrace.from_stacktrace(stacktrace)
def new(exception, stacktrace, opts) when is_list(exception) do
%__MODULE__{
errors: [Builder.build_error(exception, stacktrace)],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner 👍 👍

@jdfrens jdfrens merged commit c14c3ff into master Apr 2, 2024
17 checks passed
@jdfrens jdfrens deleted the set-session-from-logger-metadata branch April 2, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants