mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-23 00:14:48 +00:00
28 lines
816 B
Elixir
28 lines
816 B
Elixir
|
defmodule Mobilizon.GraphQL.Middleware.OperationNameLogger do
|
||
|
@moduledoc """
|
||
|
An Absinthe middleware to add to logging providers the GraphQL Operation name as context
|
||
|
"""
|
||
|
|
||
|
@behaviour Absinthe.Middleware
|
||
|
alias Absinthe.Blueprint.Document.Operation
|
||
|
|
||
|
def call(resolution, _opts) do
|
||
|
case Enum.find(resolution.path, ¤t_operation?/1) do
|
||
|
%Operation{name: name} when not is_nil(name) ->
|
||
|
Logger.metadata(graphql_operation_name: name)
|
||
|
|
||
|
if Application.get_env(:sentry, :dsn) != nil do
|
||
|
Sentry.Context.set_extra_context(%{"graphql_operation_name" => name})
|
||
|
end
|
||
|
|
||
|
_ ->
|
||
|
Logger.metadata(graphql_operation_name: "#NULL")
|
||
|
end
|
||
|
|
||
|
resolution
|
||
|
end
|
||
|
|
||
|
defp current_operation?(%Operation{current: true}), do: true
|
||
|
defp current_operation?(_), do: false
|
||
|
end
|