2022-11-23 07:27:53 +13:00
|
|
|
defmodule AshGraphql.TraceHelpers do
|
|
|
|
@moduledoc false
|
|
|
|
|
2024-04-02 07:03:06 +13:00
|
|
|
defmacro trace(domain, resource, type, name, metadata, do: body) do
|
2022-11-23 07:27:53 +13:00
|
|
|
quote do
|
|
|
|
require Ash.Tracer
|
2024-04-02 07:03:06 +13:00
|
|
|
domain = unquote(domain)
|
2022-11-23 07:27:53 +13:00
|
|
|
resource = unquote(resource)
|
|
|
|
type = unquote(type)
|
|
|
|
name = unquote(name)
|
|
|
|
metadata = unquote(metadata)
|
|
|
|
|
|
|
|
Ash.Tracer.span type,
|
2024-04-02 07:03:06 +13:00
|
|
|
AshGraphql.TraceHelpers.span_name(domain, resource, type, name),
|
|
|
|
AshGraphql.Domain.Info.tracer(domain) do
|
|
|
|
Ash.Tracer.set_metadata(AshGraphql.Domain.Info.tracer(domain), type, metadata)
|
2022-11-23 07:27:53 +13:00
|
|
|
|
2024-04-02 07:03:06 +13:00
|
|
|
Ash.Tracer.telemetry_span [:ash, Ash.Domain.Info.short_name(domain), type], metadata do
|
2022-11-23 07:27:53 +13:00
|
|
|
unquote(body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-04-02 07:03:06 +13:00
|
|
|
def span_name(domain, resource, type, name)
|
|
|
|
when is_atom(domain) and is_atom(resource) and is_atom(type) and
|
2022-11-23 07:27:53 +13:00
|
|
|
(is_atom(name) or is_binary(name)) do
|
2024-04-02 07:03:06 +13:00
|
|
|
Ash.Domain.Info.span_name(domain, resource, "#{type}.#{name}")
|
2022-11-23 07:27:53 +13:00
|
|
|
end
|
|
|
|
end
|