I am using sentry version 8.0.2 and its reporting errors perfectly for normal cases. But for the functions which I execute via Task.start it wont report errors. inside my phoenix endpoint file I have
use Sentry.PlugCapture ... plug Sentry.PlugContext
in my config I also have
config :logger, + backends: [:console, Sentry.LoggerBackend]
Configuration seems correct but I am not able to capture events. Maybe I am missing something… Any help or guidance is welcome. Thanks
@tanweerdev what is your Elixir version? Sentry expects a particular metadata to be available for logging that was only recently added to Elixir.
You can also ask Sentry to capture all log messages. Here is what I do:
config :logger, Sentry.LoggerBackend, level: :warn, excluded_domains: [:cowboy], capture_log_messages: true
2 Likes
Environment:
Elixir version (elixir -v): Elixir 1.10.2 (compiled with Erlang/OTP 21) Erlang/OTP version (erl): Erlang/OTP 21 Sentry version (mix deps): 8.0.2 Operating system: Erlang/OTP 21 Is this an umbrella application?: yes Release type (Distillery, mix release, Mix, etc.): iex -S mix phx.server
Here is issue submitted for more details
This did not help sentry capture error msgs. (I have before_send hook to confirm where I print the event). The only thing which worked is manually capturing it
Task.start(fn -> try do MyModule.function() rescue exception -> Sentry.capture_exception(exception, [stacktrace: System.stacktrace(), extra: %{extra: %{extra_information: "my extra information"}}]) end end)
Thanks @josevalim @chulkilee for your kind replies. is there any way, I can make this Task.start + try/capture a utility function and call it whenever I needed to use Task.start and it will capture errors…
I confirm I’m getting sentry via Task.start
in this case:
- Create new project
- Add sentry dep
- Add sentry logger backend (no other configuration)
config :logger, backends: [:console, Sentry.LoggerBackend] config :sentry, dsn: "http://a:b@127.0.0.1:8000/1"
- Add following to a controller function
Task.start(fn -> MyModule.function() end)
With or without phoenix integration, it sends a request - but it does not print sentry log.
I ran dummy server with python3 -m http.server 8000 --bind 127.0.0.1
to see whether my phoenix app actually sends a request.
1 Like
Note you likely don’t want to configure this in your config/config.exs, as Sentry.LoggerBackend may be loaded even before it is compiled. This will definitely be the case in umbrella projects if only part of them depend on Sentry. Instead, call Logger.add_backend(Sentry.LoggerBackend)
in your application start/2
callback. 
2 Likes