Allowing adding mfas to ignore for stacktrace logging

40 views
Skip to first unread message

Trond M

unread,
Oct 27, 2024, 11:09:14 AM10/27/24
to elixir-ecto
I find the `stacktrace: true` option for my repo to be extremely helpful when working on large applications, but I was wondering if we could perhaps make it even more helpful by allowing the user to ignore certain calls in the stacktrace?

My problem is specifically with the `assign_new` from Phoenix.LiveView.Utils which wraps a large part of my database calls.

I see from the current implementation that it returns the last call before the repo call

```
defp last_non_ecto([{mod, _, _, _} | _stacktrace], repo, last)
       when mod == repo or mod in @repo_modules,
       do: last

  defp last_non_ecto([last | stacktrace], repo, _last),
    do: last_non_ecto(stacktrace, repo, last)

  defp last_non_ecto([], _repo, last),
    do: last
```

I tried adding this as a test:

```
defp last_non_ecto([{mod, fun, arity, _} | _stacktrace], repo, last)
       when mod == repo or mod in @repo_modules or {mod, fun, arity} == {Phoenix.LiveView.Utils, :assign_new, 3},
       do: last
```
and it immediately became more helpful for me. 

I'm not sure of the API here, but would it be possible to allow the user to add mfas to ignore here?

Greg Rychlewski

unread,
Oct 27, 2024, 8:37:25 PM10/27/24
to elixir-ecto
Maybe we can give an option to let the user specify an extraction function. Otherwise it defaults to last_non_ecto

Trond M

unread,
Oct 28, 2024, 3:18:47 PM10/28/24
to elixir-ecto
Yes, that sounds like a good way to solve this!

Felipe Stival

unread,
Oct 30, 2024, 1:50:37 AM10/30/24
to elixi...@googlegroups.com
Hi,

Maybe it would be better if we supported more stacktrace "levels" instead of custom filtering? Then you could get something like:
```
Phoenix.LiveView.Utils.assign_new/3
    └ MyApp.SomeLive.handle_event/3
```

I can see it being more helpful than the current log, and it's probably easier to configure for users. Maybe we can even default to 2.

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/a21c3a18-5d2c-416c-b2b9-e7f18e9647e2n%40googlegroups.com.

Trond M

unread,
Oct 30, 2024, 5:39:30 PM10/30/24
to elixir-ecto
That's a good point! I like that solution
Reply all
Reply to author
Forward
0 new messages