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

Support propagating OpenTelemetry context #1227

Merged

Conversation

rewritten
Copy link
Contributor

@rewritten rewritten commented Feb 8, 2023

This change adds optional support for propagating OpenTelemetry contexts in tasks spawned by the Async and Batch middleware.

This allows to correlate spans in otel backends (like datadog and others), so something like

field :posts, :list_of(:post) do
  resolve fn user, _, _ -> async(fn -> PostsResolver.posts_by_user(user) end) end
end

defmodule PostsResolver do
  def posts_by_user(user) do
    OpenTelemetry.Tracer.with_span("data access: posts by user") do
      # query posts
    end
  end
end

will create a child span in the existing trace, instead of creating a totally unrelated span.

No change in client code is necessary, and users that already propagate the context manually will just have one more indirection.

@kdawgwilk
Copy link
Contributor

This is fantastic! 👏

@kdawgwilk
Copy link
Contributor

kdawgwilk commented Feb 10, 2023

Does https://github.com/spandex-project/spandex have a similar Task you can delegate to?

EDIT: created issue over there spandex-project/spandex#148

Copy link
Contributor

@benwilson512 benwilson512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge this, thanks!

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

Successfully merging this pull request may close these issues.

3 participants