diff --git a/.idea/bootstrap-python-fastapi.iml b/.idea/bootstrap-python-fastapi.iml index f15ba15c..9dfe7768 100644 --- a/.idea/bootstrap-python-fastapi.iml +++ b/.idea/bootstrap-python-fastapi.iml @@ -5,7 +5,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index d830309a..a732e4b6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + diff --git a/poetry.lock b/poetry.lock index c2e57c56..be68e67f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -730,17 +730,18 @@ doc = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-spelling"] [[package]] name = "faker" -version = "30.0.0" +version = "30.1.0" description = "Faker is a Python package that generates fake data for you." optional = false python-versions = ">=3.8" files = [ - {file = "Faker-30.0.0-py3-none-any.whl", hash = "sha256:f0a60009150736c1c033bea31aa19ae63071c9dcf10adfaf9f1a87a3add84bc8"}, - {file = "faker-30.0.0.tar.gz", hash = "sha256:bf0207af5777950054a2a3b43f4b5bdc33b585918d2b28f1dab52ac0ffe2bac0"}, + {file = "Faker-30.1.0-py3-none-any.whl", hash = "sha256:dbf81295c948270a9e96cd48a9a3ebec73acac9a153d0c854fbbd0294557609f"}, + {file = "faker-30.1.0.tar.gz", hash = "sha256:e0593931bd7be9a9ea984b5d8c302ef1cec19392585d1e90d444199271d0a94d"}, ] [package.dependencies] python-dateutil = ">=2.4" +typing-extensions = "*" [[package]] name = "fastapi" @@ -973,13 +974,13 @@ files = [ [[package]] name = "httpcore" -version = "1.0.5" +version = "1.0.6" description = "A minimal low-level HTTP client." optional = false python-versions = ">=3.8" files = [ - {file = "httpcore-1.0.5-py3-none-any.whl", hash = "sha256:421f18bac248b25d310f3cacd198d55b8e6125c107797b609ff9b7a6ba7991b5"}, - {file = "httpcore-1.0.5.tar.gz", hash = "sha256:34a38e2f9291467ee3b44e89dd52615370e152954ba21721378a87b2960f7a61"}, + {file = "httpcore-1.0.6-py3-none-any.whl", hash = "sha256:27b59625743b85577a8c0e10e55b50b5368a4f2cfe8cc7bcfa9cf00829c2682f"}, + {file = "httpcore-1.0.6.tar.gz", hash = "sha256:73f6dbd6eb8c21bbf7ef8efad555481853f5f6acdeaff1edb0694289269ee17f"}, ] [package.dependencies] @@ -990,7 +991,7 @@ h11 = ">=0.13,<0.15" asyncio = ["anyio (>=4.0,<5.0)"] http2 = ["h2 (>=3,<5)"] socks = ["socksio (==1.*)"] -trio = ["trio (>=0.22.0,<0.26.0)"] +trio = ["trio (>=0.22.0,<1.0)"] [[package]] name = "httptools" @@ -1801,27 +1802,6 @@ opentelemetry-semantic-conventions = "0.48b0" [package.extras] instruments = ["celery (>=4.0,<6.0)"] -[[package]] -name = "opentelemetry-instrumentation-fastapi" -version = "0.48b0" -description = "OpenTelemetry FastAPI Instrumentation" -optional = false -python-versions = ">=3.8" -files = [ - {file = "opentelemetry_instrumentation_fastapi-0.48b0-py3-none-any.whl", hash = "sha256:afeb820a59e139d3e5d96619600f11ce0187658b8ae9e3480857dd790bc024f2"}, - {file = "opentelemetry_instrumentation_fastapi-0.48b0.tar.gz", hash = "sha256:21a72563ea412c0b535815aeed75fc580240f1f02ebc72381cfab672648637a2"}, -] - -[package.dependencies] -opentelemetry-api = ">=1.12,<2.0" -opentelemetry-instrumentation = "0.48b0" -opentelemetry-instrumentation-asgi = "0.48b0" -opentelemetry-semantic-conventions = "0.48b0" -opentelemetry-util-http = "0.48b0" - -[package.extras] -instruments = ["fastapi (>=0.58,<1.0)"] - [[package]] name = "opentelemetry-instrumentation-httpx" version = "0.48b0" @@ -2878,13 +2858,13 @@ tests = ["pytest", "pytest-cov"] [[package]] name = "tomli" -version = "2.0.1" +version = "2.0.2" description = "A lil' TOML parser" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, + {file = "tomli-2.0.2-py3-none-any.whl", hash = "sha256:2ebe24485c53d303f690b0ec092806a085f07af5a5aa1464f3931eec36caaa38"}, + {file = "tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed"}, ] [[package]] @@ -3393,4 +3373,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.13" -content-hash = "6ec3dd628565088d9845bab515af4c48ac29848d9874e9f704c6492b9e134562" +content-hash = "e52495cbcdd97ed207e512eec28673cf9fc647a681b54d6410994fef0f39e20e" diff --git a/pyproject.toml b/pyproject.toml index 733cf233..ce04b09f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,9 @@ optional = true [tool.poetry.group.http.dependencies] fastapi = ">=0.99.0" jinja2 = "^3.1.2" -opentelemetry-instrumentation-fastapi = "*" +# We use the generic ASGI instrumentation, so that if we decide to change +# Framework it will still work consistently. +opentelemetry-instrumentation-asgi = "*" starlette-prometheus = "^0.10.0" strawberry-graphql = { version = ">=0.204.0", extras = ["debug-server"] } uvicorn = { version = "^0.31.0", extras = ["standard"] } diff --git a/src/celery_worker/__init__.py b/src/celery_worker/__init__.py index a92852a7..741fba90 100644 --- a/src/celery_worker/__init__.py +++ b/src/celery_worker/__init__.py @@ -4,6 +4,15 @@ without having to initialise the HTTP framework (or other ones) """ +from celery.signals import worker_process_init +from opentelemetry.instrumentation.celery import CeleryInstrumentor + from bootstrap import AppConfig, application_init + +@worker_process_init.connect(weak=False) +def init_celery_tracing(*args, **kwargs): + CeleryInstrumentor().instrument() # pragma: nocover + + app = application_init(AppConfig()).celery_app