Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple absinthe namespaces #972

Open
maxsalven opened this issue Nov 7, 2024 · 1 comment
Open

Multiple absinthe namespaces #972

maxsalven opened this issue Nov 7, 2024 · 1 comment
Labels

Comments

@maxsalven
Copy link

maxsalven commented Nov 7, 2024

Describe the bug

If you have multiple graphql endpoints, setting a custom namespace doesn't work.

To Reproduce

I have two graphql endpoints, /api/graphql/user and /api/graphql/admin

  scope "/api/graphql/admin" do
    pipe_through [
      MyAppWeb.GraphqlAdmin.Plug.AppsignalNamespace,
    ]

    forward("/", MyAppWeb.Plug.AbsintheAdmin,
      schema: MyAppWeb.GraphqlAdmin.Schema
    )
  end
defmodule MyAppWeb.GraphqlAdmin.Plug.AppsignalNamespace do
  def init(default), do: default

  def call(conn, _) do
    Appsignal.Span.set_namespace(Appsignal.Tracer.root_span(), "graphql_admin")
    conn
  end
end

Calls to /api/graphql/admin still end up in the graphql namespace.

This line seems to be responsible:
https://github.com/appsignal/appsignal-elixir/blob/main/lib/appsignal/absinthe.ex#L55

Could you modify it to conditionally apply the namespace only if it's currently set to the default?

@maxsalven maxsalven added the bug label Nov 7, 2024
@jeffkreeftmeijer
Copy link
Member

Hey @maxsalven!

Thanks for raising this issue. I've taken a look at the code you posted, and it looks like you're spot on. The Absinthe integration sets the span's namespace whenever it's started. Your plug runs before the Absinthe span is started, so it doesn't set a namespace if no root span has been started.

One way to resolve this is to set the namespace after the span has been started. For example, you could set the namespace while resolving the request or requesting data from the database.

We can't currently conditionally apply the namespace, because we pass the namespace to the agent immediately. That being a one-way data pipeline, we can't determine if the namespace has been set previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants