Add GraphQL operation name, user ID and actor name in logs

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2022-11-06 11:57:53 +01:00
parent de8433cdbb
commit 30b0d3ca08
5 changed files with 38 additions and 5 deletions

View File

@@ -18,7 +18,13 @@ defmodule Mobilizon.GraphQL.Middleware.CurrentActorProvider do
case Cachex.fetch(:default_actors, to_string(user_id), fn -> default(user) end) do
{status, %Actor{preferred_username: preferred_username} = current_actor}
when status in [:ok, :commit] ->
Sentry.Context.set_user_context(%{name: preferred_username})
Logger.metadata(user_id: user_id)
Logger.metadata(actor_name: "@" <> preferred_username)
if Application.get_env(:sentry, :dsn) != nil do
Sentry.Context.set_user_context(%{name: preferred_username})
end
context = Map.put(context, :current_actor, current_actor)
%Absinthe.Resolution{resolution | context: context}