-
Notifications
You must be signed in to change notification settings - Fork 628
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
fix(opentelemetry-instrumentation-celery): attach incoming context on… #2385
fix(opentelemetry-instrumentation-celery): attach incoming context on… #2385
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a newbie I find it a bit strange to expect to use the baggage to pass metadata implicitly to the celery worker. If the span has the baggage context I don't see it as a bug.
@xrmx Other implementations like the django one, make use of this function that I believe it implies that if there's no active span it should extract the context from the carrier, attach and then creates a span. As another reference, the kafka client does the context.attach after creating the span here. Unless I'm misunderstanding your concerns and there is a better way to achieve this. |
I guess I have taken the example too literally :) |
@xrmx Yes, I realized that too. I pushed a new commit that adds the detache of the context and moved the PR to draft for now until I write some tests for the new functions. Should have it ready tonight. |
@xrmx Thanks for your patience. This should be good for review now. |
...on/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@malcolmrebughini docker-tests are broken.
...on/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py
Show resolved
Hide resolved
@xrmx I'm unable to run these test locally to debug. Any pointers? I run
I have libpq and snappy as indicated in the contributing instructions. |
You need |
@xrmx hi again. I've been away for a bit. I was able to fix the docker tests on my latest commit. Please take another look. |
I've tested this PR in my local environment and it seems to be working quite nicely. I noticed that context doesn't get propagated in It'd be great if maintainers could look into the PR before the next release. |
@rbagd thanks for trying it out. Can you provide more details on what you mean that the context doesn't get propagated in |
@malcolmrebughini So from what I understood Celery instrumentation registers a I didn't see an obvious way to change the ordering of P.S. This is not specific to this PR, it must have been there from the start. |
@malcolmrebughini please rebase and move the changelog update to the unreleased section |
65ceb1a
to
59f63fc
Compare
@xrmx done with the rebase and added the changelog entry to unreleased 👌 |
e858553
to
109a04f
Compare
109a04f
to
39482d4
Compare
self.update_task_duration_time(task_id) | ||
labels = {"task": task.name, "worker": task.request.hostname} | ||
self._record_histograms(task_id, labels) | ||
context_api.detach(token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this line introduces a bug where the token could be "None" if the prerun signal has no traceparent.
This could happen for example if the process sending the task isn't instrumented, while the celery worker is instrumented. This results in an error since token cannot be None when calling context_api.detach()
This seems related as well: open-telemetry/opentelemetry-python#4163
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a silly mistake on my end. I'll get a fix for this tonight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
started a draft PR here: #2855
still trying to figure out how to write a test for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an integration test is hard to write maybe an unit test could help in moving things forward
… _trace_prerun
Description
Currently incoming baggage does not get picked up. So this PR applies the fix described in the original issue.
Fixes #784
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
The original issue has steps to reproduce.
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.