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

opentelemetry-instrumentation-celery: don't detach a None token #2927

Merged
merged 4 commits into from
Oct 28, 2024

Conversation

xrmx
Copy link
Contributor

@xrmx xrmx commented Oct 28, 2024

Description

Don't detach a None token in postrun.

Avoids this in celery logs:

[2024-10-28 12:14:18,868: ERROR/MainProcess] Failed to detach context
    Traceback (most recent call last):
      File "/home/rm/src/opentelemetry-python-contrib/.tox/py310-test-instrumentation-celery-1/lib/python3.10/site-packages/opentelemetry/context/__init__.py", line 152, in detach
        _RUNTIME_CONTEXT.detach(token)
      File "/home/rm/src/opentelemetry-python-contrib/.tox/py310-test-instrumentation-celery-1/lib/python3.10/site-packages/opentelemetry/context/contextvars_context.py", line 50, in detach
        self._current_context.reset(token)  # type: ignore
    TypeError: expected an instance of Token, got None

Since celery catches everything this does not change anything in practice. I've added a test that exercise the error but I have no clue on how to get celery stdout. I've tested that with pytest -s we don't get the message.

Closes #2855

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • tox

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

malcolmrebughini and others added 3 commits October 28, 2024 12:22
Without the fix we have this in stdout:

[2024-10-28 12:14:18,868: ERROR/MainProcess] Failed to detach context
Traceback (most recent call last):
  File "/home/rm/src/opentelemetry-python-contrib/.tox/py310-test-instrumentation-celery-1/lib/python3.10/site-packages/opentelemetry/context/__init__.py", line 152, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "/home/rm/src/opentelemetry-python-contrib/.tox/py310-test-instrumentation-celery-1/lib/python3.10/site-packages/opentelemetry/context/contextvars_context.py", line 50, in detach
    self._current_context.reset(token)  # type: ignore
TypeError: expected an instance of Token, got None
@xrmx xrmx requested a review from a team as a code owner October 28, 2024 11:33
@xrmx xrmx changed the title opentelemetry-instrumentation-celery: don't teach a None token opentelemetry-instrumentation-celery: don't detach a None token Oct 28, 2024
@lzchen lzchen merged commit 7cbe586 into open-telemetry:main Oct 28, 2024
536 checks passed
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