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

Accept structs as structured logs in Sentry.LoggerHandler #780

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

mrdotb
Copy link
Contributor

@mrdotb mrdotb commented Aug 29, 2024

👋

While testing my custom logger handler, which is based on the Sentry Elixir handler, I encountered an issue where passing a struct to Logger.error causes the handler to detach. The error handler only supports keywords and maps.

The problem arose when using the Tesla library, which passes a Tesla.Env struct to Logger.error. Interestingly, Logger.info does support passing structs, and the struct is displayed as a keyword list or map with the __struct__ field

iex(3)> Logger.error(%Foo{})
:ok
23:36:43.117 [error] [__struct__: Foo, bar: nil]

I added a test that reproduce the issue and a fix proposition.

@whatyouhide whatyouhide changed the title logger_handler getting detached when passing a struct Accept structs as structured logs in Sentry.LoggerHandler Sep 2, 2024
Copy link
Collaborator

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

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

Great catch, thanks @mrdotb 💟

@whatyouhide whatyouhide merged commit bcdcc04 into getsentry:master Sep 2, 2024
4 checks passed
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.

2 participants