-
Notifications
You must be signed in to change notification settings - Fork 190
Open
Labels
Description
Description
Hi, I am not able to get logfire working on Cloudflare workers (python), because logfire does not work using pyodide
Reproduction
pyproject.toml
[project]
name = "logfire-cf-workers"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"fastapi>=0.124.4",
"logfire[fastapi]>=4.16.0",
]
[dependency-groups]
dev = [
"workers-py>=1.7.0",
"workers-runtime-sdk>=0.3.1",
]
main.py
import logfire # this line causes the error
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return "HELLO WORLD"
try:
from workers import WorkerEntrypoint
import asgi
class Default(WorkerEntrypoint):
async def fetch(self, request):
return await asgi.fetch(app, request, self.env)
except (ModuleNotFoundError, ImportError):
passwrangler.jsonc
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "worker",
"main": "main.py",
"compatibility_date": "2025-11-02",
"compatibility_flags": [
"python_workers"
],
"vars": {
},
"observability": {
"enabled": true
}
}Then run:
uv run pywrangler devError:
✘ [ERROR] service core:user:worker: Uncaught Error: PythonError: Traceback (most recent call last):
File "/lib/python313.zip/_pyodide/_base.py", line 666, in pyimport_impl
res = __import__(stem, fromlist=fromlist)
File "/session/metadata/main.py", line 1, in <module>
import logfire
File "/session/metadata/python_modules/logfire/__init__.py", line 7, in <module>
from logfire.propagate import attach_context, get_context
File "/session/metadata/python_modules/logfire/propagate.py", line 20, in <module>
from opentelemetry import context as otel_context, propagate, trace
File "/session/metadata/python_modules/opentelemetry/context/__init__.py", line 163, in <module>
_SUPPRESS_INSTRUMENTATION_KEY = create_key("suppress_instrumentation")
File "/session/metadata/python_modules/opentelemetry/context/__init__.py", line 82, in
create_key
return keyname + "-" + str(uuid4())
~~~~~^^
File "/lib/python313.zip/uuid.py", line 712, in uuid4
return UUID(bytes=os.urandom(16), version=4)
~~~~~~~~~~^^^^
File "/lib/python3.13/site-packages/_cloudflare/entropy_patches.py", line 49, in patch_urandom
raise_unless_entropy_allowed()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/lib/python3.13/site-packages/_cloudflare/allow_entropy.py", line 34, in
raise_unless_entropy_allowed
raise OSError(EIO, "Cannot get entropy outside of request context")
OSError: [Errno 29] Cannot get entropy outside of request context
at null.<anonymous> (pyodide-internal:generated/emscriptenSetup:19872:14) in new_error
at [object Object] in $wrap_exception
at [object Object] in $pythonexc2js
at null.<anonymous> (pyodide-internal:generated/emscriptenSetup:22390:15) in
callPyObjectKwargsPromising