Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Enable the OpenTelemetry threading instrumentor by default (#19951)

Marcin Wcisło01650613a0df
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 533cfcf3b5..36beae6b79 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,7 +68,7 @@ All notable, unreleased changes to this project will be documented in this file.
### Other changes
-- Added OpenTelemetry instrumentation for psycopg, Celery, Redis, requests and botocore. Spans for database queries, cache and broker commands, Celery tasks, outgoing HTTP requests and AWS calls are now emitted alongside Saleor's own spans, with Celery task spans linked to the request that scheduled them. Library instrumentors emit spans only, their metrics are not exported. The set of enabled instrumentors is controlled by the new `TELEMETRY_INSTRUMENTORS` environment variable, which takes a comma-separated list of OpenTelemetry instrumentor entry point names and defaults to `psycopg,celery,redis,requests,botocore`. Set it to an empty string to disable library instrumentation. The OpenTelemetry packages were upgraded to SDK 1.37.0 and instrumentation 0.58b0.
+- Added OpenTelemetry instrumentation for psycopg, Celery, Redis, requests and botocore. Spans for database queries, cache and broker commands, Celery tasks, outgoing HTTP requests and AWS calls are now emitted alongside Saleor's own spans, with Celery task spans linked to the request that scheduled them. The threading instrumentor is enabled too, so spans created in threads and thread pools, for example S3 calls that boto3 runs in its transfer threads, stay in the trace of the request or task that started them. Library instrumentors emit spans only, their metrics are not exported. The set of enabled instrumentors is controlled by the new `TELEMETRY_INSTRUMENTORS` environment variable, which takes a comma-separated list of OpenTelemetry instrumentor entry point names and defaults to `psycopg,celery,redis,requests,botocore,threading`. Set it to an empty string to disable library instrumentation. The OpenTelemetry packages were upgraded to SDK 1.37.0 and instrumentation 0.58b0.
- Dropped the database leftovers of the legacy digital content feature removed in 3.23: the `product_digitalcontent` and `product_digitalcontenturl` tables, and the `automatic_fulfillment_digital_products`, `default_digital_max_downloads` and `default_digital_url_valid_days` columns of `site_sitesettings`. Files uploaded through the legacy API are not removed from the media storage — the `digital_contents/` directory can be deleted manually.
- `ProductType.is_digital` was removed from the ORM model; the column itself will be dropped in 3.25.
- Removed the `is_digital` field from the `populatedb` sample data.
diff --git a/pyproject.toml b/pyproject.toml
index b74314e265..df65b1830a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -74,6 +74,7 @@ dependencies = [
"opentelemetry-instrumentation-psycopg>=0.58b0,<0.59",
"opentelemetry-instrumentation-redis>=0.58b0,<0.59",
"opentelemetry-instrumentation-requests>=0.58b0,<0.59",
+ "opentelemetry-instrumentation-threading>=0.58b0,<0.59",
"celery[redis, sqs]>=5.6.3,<6.0.0",
"kombu[sqs]>=4.6.11,<6.0.0",
"django-storages[google]~=1.11",
@@ -231,7 +232,7 @@ pillow = "PIL"
python-magic-bin = "magic"
[tool.deptry.per_rule_ignores]
-DEP002 = ["azure-common", "azure-storage-blob", "azure-storage-common", "django-redis", "psycopg", "pyxb", "opentelemetry-instrumentation-botocore", "opentelemetry-instrumentation-celery", "opentelemetry-instrumentation-psycopg", "opentelemetry-instrumentation-redis", "opentelemetry-instrumentation-requests"]
+DEP002 = ["azure-common", "azure-storage-blob", "azure-storage-common", "django-redis", "psycopg", "pyxb", "opentelemetry-instrumentation-botocore", "opentelemetry-instrumentation-celery", "opentelemetry-instrumentation-psycopg", "opentelemetry-instrumentation-redis", "opentelemetry-instrumentation-requests", "opentelemetry-instrumentation-threading"]
[tool.django-stubs]
django_settings_module = "saleor.settings"
diff --git a/saleor/core/telemetry/tests/test_init.py b/saleor/core/telemetry/tests/test_init.py
index 881acde9dd..efd0fadff6 100644
--- a/saleor/core/telemetry/tests/test_init.py
+++ b/saleor/core/telemetry/tests/test_init.py
@@ -7,7 +7,14 @@ from opentelemetry.metrics import NoOpMeterProvider
from .. import initialize_telemetry, instrument_libraries
-DEFAULT_INSTRUMENTORS = ["psycopg", "celery", "redis", "requests", "botocore"]
+DEFAULT_INSTRUMENTORS = [
+ "psycopg",
+ "celery",
+ "redis",
+ "requests",
+ "botocore",
+ "threading",
+]
class Invalid:
diff --git a/saleor/settings.py b/saleor/settings.py
index fa8353dd68..dd16a413e1 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -1218,10 +1218,15 @@ TELEMETRY_METER_CLASS = "saleor.core.telemetry.metric.Meter"
# OpenTelemetry library instrumentors enabled when telemetry is initialized, by
# entry point name in the `opentelemetry_instrumentor` group (registered by the
# opentelemetry-instrumentation-* packages). They produce spans for database
-# queries, cache and broker calls, outgoing HTTP requests and Celery tasks.
+# queries, cache and broker calls, outgoing HTTP requests and Celery tasks. The
+# threading instrumentor produces no spans of its own, it carries the current trace
+# context into threads and thread pools (for example the ones boto3 uses for S3
+# uploads and downloads), so spans created there keep their parent.
# Set to an empty string to disable library instrumentation.
TELEMETRY_INSTRUMENTORS = get_list(
- os.environ.get("TELEMETRY_INSTRUMENTORS", "psycopg,celery,redis,requests,botocore")
+ os.environ.get(
+ "TELEMETRY_INSTRUMENTORS", "psycopg,celery,redis,requests,botocore,threading"
+ )
)
# Whether to raise or log exceptions for telemetry unit conversion errors
# Disabled by default to prevent disruptions caused by unexpected unit conversion issues
diff --git a/uv.lock b/uv.lock
index d2d437db7d..a71a6f59ff 100644
--- a/uv.lock
+++ b/uv.lock
@@ -1717,6 +1717,20 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/90/4d/f3476b28ea167d1762134352d01ae9693940a42c78994d9f1b32a4477816/opentelemetry_instrumentation_requests-0.58b0-py3-none-any.whl", hash = "sha256:672a0be0bb5b52bea0c11820b35e27edcf4cd22d34abe4afc59a92a80519f8a8", size = 12966, upload-time = "2025-09-11T11:41:52.67Z" },
]
+[[package]]
+name = "opentelemetry-instrumentation-threading"
+version = "0.58b0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "opentelemetry-api" },
+ { name = "opentelemetry-instrumentation" },
+ { name = "wrapt" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/70/a9/3888cb0470e6eb48ea17b6802275ae71df411edd6382b9a8e8f391936fda/opentelemetry_instrumentation_threading-0.58b0.tar.gz", hash = "sha256:f68c61f77841f9ff6270176f4d496c10addbceacd782af434d705f83e4504862", size = 8770, upload-time = "2025-09-11T11:42:56.308Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/a5/54/add1076cb37980e617723a96e29c84006983e8ad6fc589dde7f69ddc57d4/opentelemetry_instrumentation_threading-0.58b0-py3-none-any.whl", hash = "sha256:eacc072881006aceb5b9b6831bcdce718c67ef6f31ac0b32bd6a23a94d979b4a", size = 9312, upload-time = "2025-09-11T11:41:58.603Z" },
+]
+
[[package]]
name = "opentelemetry-propagator-aws-xray"
version = "1.0.2"
@@ -2628,6 +2642,7 @@ dependencies = [
{ name = "opentelemetry-instrumentation-psycopg" },
{ name = "opentelemetry-instrumentation-redis" },
{ name = "opentelemetry-instrumentation-requests" },
+ { name = "opentelemetry-instrumentation-threading" },
{ name = "opentelemetry-sdk" },
{ name = "opentelemetry-semantic-conventions" },
{ name = "orjson" },
@@ -2739,6 +2754,7 @@ requires-dist = [
{ name = "opentelemetry-instrumentation-psycopg", specifier = ">=0.58b0,<0.59" },
{ name = "opentelemetry-instrumentation-redis", specifier = ">=0.58b0,<0.59" },
{ name = "opentelemetry-instrumentation-requests", specifier = ">=0.58b0,<0.59" },
+ { name = "opentelemetry-instrumentation-threading", specifier = ">=0.58b0,<0.59" },
{ name = "opentelemetry-sdk", specifier = ">=1.37.0,<2" },
{ name = "opentelemetry-semantic-conventions", specifier = ">=0.58b0,<0.59" },
{ name = "orjson", specifier = ">=3.11.9" },