-
Notifications
You must be signed in to change notification settings - Fork 125
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
Dataloader - try to first fetch self ctx in run start #162
base: main
Are you sure you want to change the base?
Conversation
@afloram you probably just need to use process propagator in your code rather than modifying this library. https://hexdocs.pm/opentelemetry_process_propagator/OpentelemetryProcessPropagator.Task.html |
@bryannaegele That module seems nice, it allows for the |
Yeah, I don't know enough about how the two libraries interact or work. @maartenvanvliet |
If it is run in a Task wouldn't it first find the context of the process that runs the Task? So this must mean you aren't setting a current context in the wrapper you have? |
Both Absinthe and Dataloader use the |
The process that runs the Task as in the process where the function given to This might be a bit long but I think it can clear things up: In the wrapper we are at process Then the Absinthe instrumentation library, still at process With the PR changes the Dataloader instrumentation library would first look for the As I mentioned before, I directly got the idea of first looking at |
Oh nice, just now noticing the comment that absinthe and dataloader have accepted PRs to integrate OpenTelemetry process propagator! |
@afloram |
@tsloughter makes sense, you're right. Initially I just commented out the Should I just do no |
@afloram right, no attach should be needed and no detach should be done of the parent. |
@afloram ping? |
Sorry for the late update @tsloughter. I removed the self attach and the parent detach parts as you suggested. I tested it for our use case and the traces still come out nicely 👍 |
What does this PR do?
The Dataloader instrumentation's
[:dataloader, :source, :run, :start]
event handler now first tries to fetch a parent context fromself()
before checking the:"$callers"
.Context
I was trying out the recently merged (thanks!) dataloader instrumentation, and while it seems to work great, I encountered an issue with a specific situation on our end.
Basically, we have a wrapper around
Absinthe.Plug
which calls the actualAbsinthe.Plug.call/2
insideTask.async/1
. This means that said call happens in a child process, which caused the Dataloader spans to appear as children of the Phoenix span (usingopentelemetry_phoenix
) instead of being children of the Absinthe span (using theopentelemetry_absinthe
outside of this repo).It was caused by this part of the code, which grabbed the context from the parent process (the one which used
async/1
):To solve it, I used
OpenTelemetry.Tracer.set_current_span/1
to pass the context from the caller process into the async task one in our code, and modified the Dataloader instrumentation library to first try to look for theself()
context before looking at the:"$callers"
. The latter part is practically taken right out of this part ofopentelemetry_ecto
. This was only done for therun
events because they are the parent Dataloader spans, under which thebatch
ones reside.Additionally, just like in
opentelemetry_ecto
, we useOpenTelemetry.Ctx.detach/1
at therun
stop. For storing the context for the eventual detachment I got the idea from this part ofopentelemetry_absinthe
. As a note, even if this detachment is not performed everything seems to work properly, but it seemed like the 'correct' thing to do, even though I'm not sure.I just started looking into OTEL a few days ago and basically thought about this 'solution' by fiddling around and taking direct inspiration from the
opentelemetry_ecto
andopentelemetry_absinthe
code, so I understand if the correct approach is a completely different one, and I'm open to hear about it.