marcandre

marcandre

Some sentry errors from live_view have no context

Most of our production errors in sentry have the expected context: HTTP request, params, cookies, etc. This is great. Some errors do not, which makes them impossible to diagnose.

For example, I have this particular view that crashes in circumstances yet unknown. I’m getting events with the context and the following stacktrace:

This has all the relevant information.

The “same” exception occurs with a different call stack and then I get no information:

Using Liveview 0.18.2.

What is going on?
What can be done about it?

Most Liked

josevalim

josevalim

Creator of Elixir

If it helps, here is some code that we used in Bytepack to store LiveView information:

https://github.com/dashbitco/bytepack_archive/blob/main/apps/bytepack_web/lib/bytepack_web/request_context.ex

The audit context is passed to the context/model layer. The request context is stored in Sentry’s pdict.

LostKobrakai

LostKobrakai

Just to make this a bit more explicit. When thing fail on the websocket connection there is no http request to have information about in the first place. Cookies (of the initial upgrade request) are also not exposed to channels. Relevant information would need to be fetched through other means, which I’m not sure the sentry library has integrations for yet.

ruslandoga

ruslandoga

:waving_hand:

Sentry uses process dict to store context, similar to Logger. Sentry plug sets the context on the process that handles the HTTP requests and the first liveview render. I guess your problem arises when the error happens in the live view’s channel process (apparently in handle_info) which has no context set by Sentry.

def mount(_, _, socket) do
  ctx = Sentry.Context.get_all()
  
  if connected?(socket) do
    IO.inspect(ctx, label: "live view channel context")
  else
    IO.inspect(ctx, label: "live view first http request context")
  end

  {:ok, socket}
end

If that’s indeed the case, then you can probably add an on_mount hook that would copy the context from HTTP request into the channel process.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement