getsentry / sentry-elixir

The official Elixir SDK for Sentry (sentry.io)
https://sentry.io
MIT License
627 stars 185 forks source link

Accept structs as structured logs in Sentry.LoggerHandler #780

Closed mrdotb closed 2 months ago

mrdotb commented 3 months ago

👋

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.