Solution skill
Logfire with Celery ingores `token`
Complete solution
Shows how to fix logfire with Celery ingores `token`. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
When it applies
Not specified by the original author.
Instructions
TL;DR
If Logfire with Celery throws 'Failed to detach context' errors, update with pip install -U 'logfire[celery]' (logfire 2.7.0 and opentelemetry-instrumentation-celery 0.49b2 are the versions the reporter confirmed fixed it).
Steps
- If Logfire with Celery throws 'Failed to detach context' errors, update with pip install -U 'logfire[celery]' (logfire 2.7.0 and opentelemetry-instrumentation-celery 0.49b2 are the versions the reporter confirmed fixed it). Also note the docs hook logfire.instrumentcelery() to the workerinit signal, not workerprocessinit.
- Source: https://github.com/pydantic/logfire/issues/653 (Pydantic Logfire)
When to use
You are seeing this: Also note the docs hook logfire.instrumentcelery() to the workerinit signal, not workerprocessinit. Source: https://github.com/pydantic/logfire/issues/653 (Pydantic Logfire) Use this skill when you run into "Logfire with Celery ingores token".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: logfire 2.7.0. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Edge cases
- Also note the docs hook logfire.instrumentcelery() to the workerinit signal, not workerprocessinit. Source: https://github.com/pydantic/logfire/issues/653 (Pydantic Logfire)
Sources
- https://github.com/pydantic/logfire/issues/653
Evidence
In gh:pydantic/logfire#653, the issue was: ### Description
Hello!
I'm running pytest with Celery (5.4.0) worker in Docker containers without a token and after each task I get the following output:
celery-worker-test-1 | 2024-12-07T11:16:39.350795862Z Traceback (most recent call last):
celery-worker-test-1 | 2024-12-07T11:16:39.350805992Z File "/usr/local/lib/python3.10/site-packages/opentelemetry/context/__init__.py", line 154, in detach
celery-worker-test-1 | 2024-12-07T11:16:39.350810430Z _RUNTIME_CONTEXT.detach(token)
celery-worker-test-1 | 2024-12-07T11:16:39.350814298Z File.... The verified answer: If Logfire with Celery throws 'Failed to detach context' errors, update with pip install -U 'logfire[celery]' (logfire 2.7.0 and opentelemetry-instrumentation-celery 0.49b2 are the versions the reporter confirmed fixed it). Also note the docs hook logfire.instrument_celery() to the worker_init signal, not worker_process_init.. Issue URL: https://github.com/pydantic/logfire/issues/653By @issueatlas · Version 2 · Exact version
Maintainer review
Checking maintainer review for this exact version…
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_F1ycH6tWNd4eGAH3cnLKGg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Logfire with Celery ingores `token` <span>— Vectle</span></a>