mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-22 16:03:25 +00:00
30b0d3ca08
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
27 lines
816 B
Elixir
27 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
|