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

Propagate OpenTelemetry context in tasks #152

Merged

Conversation

rewritten
Copy link
Contributor

When using OpenTelemetry to create trace spans, the context is not automatically propagated to child tasks. This results in spans that have no correlation with their parent, which makes it worthless to trace.

One could wrap everything by hand (for instance, saving the original OTel context in a field of a source, and attaching to it in its run/1 protocol implementation) but it is repetitive and error-prone.

This change automatically attaches the context to every spawned task, so it is already available for creating spans with

OpenTelemetry.Tracer.with_span("My span") do
  # inside a span
end

or to open and close spans in :telemetry handlers (which are run in the child processes)

See also the following PR that adds the same support to absinthe.

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.

Hey @rewritten thanks so much for the PR, this approach looks spot on! I'm not entirely sure why we're getting warnings, let me pull this down and see if I can sort it out.

@rewritten
Copy link
Contributor Author

rewritten commented Feb 9, 2023

It says

Warning: Function OpentelemetryProcessPropagator.Task.async/1 does not exist.

That is weird, but I haven't tested it with OTP 25 because absinthe's own tests fail with that version. I'll run tests under OTP 25.

--- edit

Tests were fine, but dialyzer does not take into account dependencies that are not connected to a runtime app by default.

@rewritten
Copy link
Contributor Author

rewritten commented Feb 9, 2023

@benwilson512 this config shows a deprecated option but there is no alternative for dialyxir to take dependencies into account. I have opened an issue with them about that.


Update: There was a different option to plt_add_deps that I missed

Update 2: It was only about adding :opentelemetry_process_propagator to the additional apps. I thought it was not working, but I might have been bitten by a typo. Now it should work as expected.

@rewritten
Copy link
Contributor Author

@benwilson512 the type issues are solved. Do you think it can be merged?

@benwilson512 benwilson512 merged commit 9381dd5 into absinthe-graphql:master Feb 15, 2023
@benwilson512
Copy link
Contributor

This looks great, 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.

2 participants