From a897a959b95470f95fdff3e3e3719bc069a9e2e4 Mon Sep 17 00:00:00 2001 From: mriamah Date: Mon, 25 Aug 2025 11:45:17 +0100 Subject: [PATCH 1/6] Update celery instrumentation to follow semantic conventions --- .../src/opentelemetry/instrumentation/celery/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 908f158507..045549a7c6 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -76,7 +76,9 @@ def add(x, y): from opentelemetry.metrics import get_meter from opentelemetry.propagate import extract, inject from opentelemetry.propagators.textmap import Getter -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes import ( + messaging_attributes as SpanAttributes, +) from opentelemetry.trace.status import Status, StatusCode if VERSION >= (4, 0, 1): @@ -128,7 +130,7 @@ def _instrument(self, **kwargs): __name__, __version__, tracer_provider, - schema_url="https://opentelemetry.io/schemas/1.11.0", + schema_url="https://opentelemetry.io/schemas/1.35.0", ) meter_provider = kwargs.get("meter_provider") @@ -136,7 +138,7 @@ def _instrument(self, **kwargs): __name__, __version__, meter_provider, - schema_url="https://opentelemetry.io/schemas/1.11.0", + schema_url="https://opentelemetry.io/schemas/1.35.0", ) self.create_celery_metrics(meter) From 0bb7870105000bcae33711c41db631bd90dac2e2 Mon Sep 17 00:00:00 2001 From: mriamah Date: Mon, 25 Aug 2025 12:36:23 +0100 Subject: [PATCH 2/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index af4d00eb6c..8cb68f2c46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3610)) - infra(ci): Fix git pull failures in core contrib test ([#3357](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3357)) +- `opentelemetry-instrumentation-celery`: Bump celery semantic convention schema version from 1.11.0 to 1.35.0 + ([#3712](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3712)) ### Added From 8dc6ea7953ecb1aa333a0aa91228ae434cb1b50b Mon Sep 17 00:00:00 2001 From: mriamah Date: Wed, 27 Aug 2025 13:28:52 +0100 Subject: [PATCH 3/6] Update celery instrumentation to follow semantic conventions --- .../src/opentelemetry/instrumentation/celery/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py index d7ca77af8a..9235b4752d 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -20,7 +20,9 @@ from celery import registry # pylint: disable=no-name-in-module from celery.app.task import Task -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes import ( + messaging_attributes as SpanAttributes, +) from opentelemetry.trace import Span if TYPE_CHECKING: @@ -92,7 +94,7 @@ def set_attributes_from_context(span, context): if routing_key is not None: span.set_attribute( - SpanAttributes.MESSAGING_DESTINATION, routing_key + SpanAttributes.MESSAGING_DESTINATION_NAME, routing_key ) value = str(value) @@ -101,14 +103,13 @@ def set_attributes_from_context(span, context): attribute_name = SpanAttributes.MESSAGING_MESSAGE_ID elif key == "correlation_id": - attribute_name = SpanAttributes.MESSAGING_CONVERSATION_ID + attribute_name = SpanAttributes.MESSAGING_MESSAGE_CONVERSATION_ID elif key == "routing_key": - attribute_name = SpanAttributes.MESSAGING_DESTINATION + attribute_name = SpanAttributes.MESSAGING_DESTINATION_NAME # according to https://docs.celeryproject.org/en/stable/userguide/routing.html#exchange-types elif key == "declare": - attribute_name = SpanAttributes.MESSAGING_DESTINATION_KIND for declare in value: if declare.exchange.type == "direct": value = "queue" From 90666fca03fdfb4f72069ae2072c87ce2fad5396 Mon Sep 17 00:00:00 2001 From: mriamah Date: Wed, 27 Aug 2025 13:29:58 +0100 Subject: [PATCH 4/6] Update celery instrumention tests to follow semantic conventions --- .../tests/test_tasks.py | 25 +++++++++++-------- .../tests/test_utils.py | 11 +++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py index c68b1bc758..9b48e9e11e 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py @@ -20,7 +20,12 @@ from opentelemetry import baggage, context from opentelemetry.instrumentation.celery import CeleryInstrumentor, utils from opentelemetry.instrumentation.utils import unwrap -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes import ( + exception_attributes as ExceptionAttributes, +) +from opentelemetry.semconv._incubating.attributes import ( + messaging_attributes as SpanAttributes, +) from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind, StatusCode @@ -65,7 +70,7 @@ def test_task(self): { "celery.action": "run", "celery.state": "SUCCESS", - SpanAttributes.MESSAGING_DESTINATION: "celery", + SpanAttributes.MESSAGING_DESTINATION_NAME: "celery", "celery.task_name": "tests.celery_test_tasks.task_add", }, ) @@ -83,8 +88,7 @@ def test_task(self): { "celery.action": "apply_async", "celery.task_name": "tests.celery_test_tasks.task_add", - SpanAttributes.MESSAGING_DESTINATION_KIND: "queue", - SpanAttributes.MESSAGING_DESTINATION: "celery", + SpanAttributes.MESSAGING_DESTINATION_NAME: "celery", }, ) @@ -117,7 +121,7 @@ def test_task_raises(self): { "celery.action": "run", "celery.state": "FAILURE", - SpanAttributes.MESSAGING_DESTINATION: "celery", + SpanAttributes.MESSAGING_DESTINATION_NAME: "celery", "celery.task_name": "tests.celery_test_tasks.task_raises", }, ) @@ -127,15 +131,17 @@ def test_task_raises(self): self.assertEqual(1, len(consumer.events)) event = consumer.events[0] - self.assertIn(SpanAttributes.EXCEPTION_STACKTRACE, event.attributes) + self.assertIn( + ExceptionAttributes.EXCEPTION_STACKTRACE, event.attributes + ) # TODO: use plain assertEqual after 1.25 is released (https://github.com/open-telemetry/opentelemetry-python/pull/3837) self.assertIn( - "CustomError", event.attributes[SpanAttributes.EXCEPTION_TYPE] + "CustomError", event.attributes[ExceptionAttributes.EXCEPTION_TYPE] ) self.assertEqual( - event.attributes[SpanAttributes.EXCEPTION_MESSAGE], + event.attributes[ExceptionAttributes.EXCEPTION_MESSAGE], "The task failed!", ) @@ -148,8 +154,7 @@ def test_task_raises(self): { "celery.action": "apply_async", "celery.task_name": "tests.celery_test_tasks.task_raises", - SpanAttributes.MESSAGING_DESTINATION_KIND: "queue", - SpanAttributes.MESSAGING_DESTINATION: "celery", + SpanAttributes.MESSAGING_DESTINATION_NAME: "celery", }, ) diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py index a2f6e4338c..39f70e3472 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py @@ -20,7 +20,9 @@ from opentelemetry import trace as trace_api from opentelemetry.instrumentation.celery import utils from opentelemetry.sdk import trace -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.semconv._incubating.attributes import ( + messaging_attributes as SpanAttributes, +) class TestUtils(unittest.TestCase): @@ -51,11 +53,14 @@ def test_set_attributes_from_context(self): "44b7f305", ) self.assertEqual( - span.attributes.get(SpanAttributes.MESSAGING_CONVERSATION_ID), + span.attributes.get( + SpanAttributes.MESSAGING_MESSAGE_CONVERSATION_ID + ), "44b7f305", ) self.assertEqual( - span.attributes.get(SpanAttributes.MESSAGING_DESTINATION), "celery" + span.attributes.get(SpanAttributes.MESSAGING_DESTINATION_NAME), + "celery", ) self.assertEqual( From 73d33100f2287f82265875f16e64bc38084ae6d2 Mon Sep 17 00:00:00 2001 From: mriamah Date: Wed, 27 Aug 2025 13:42:44 +0100 Subject: [PATCH 5/6] Update celery instrumentation to use latest semantic conventions schema version --- .../src/opentelemetry/instrumentation/celery/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 045549a7c6..cb7f6afbf8 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -130,7 +130,7 @@ def _instrument(self, **kwargs): __name__, __version__, tracer_provider, - schema_url="https://opentelemetry.io/schemas/1.35.0", + schema_url="https://opentelemetry.io/schemas/1.37.0", ) meter_provider = kwargs.get("meter_provider") @@ -138,7 +138,7 @@ def _instrument(self, **kwargs): __name__, __version__, meter_provider, - schema_url="https://opentelemetry.io/schemas/1.35.0", + schema_url="https://opentelemetry.io/schemas/1.37.0", ) self.create_celery_metrics(meter) From 9a33772afc3d57d4eccfa2c97d09fa7b69f799c0 Mon Sep 17 00:00:00 2001 From: mriamah Date: Wed, 27 Aug 2025 13:43:38 +0100 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cb68f2c46..16e22a5b64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3610)) - infra(ci): Fix git pull failures in core contrib test ([#3357](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3357)) -- `opentelemetry-instrumentation-celery`: Bump celery semantic convention schema version from 1.11.0 to 1.35.0 +- `opentelemetry-instrumentation-celery`: Bump celery semantic convention schema version from 1.11.0 to 1.37.0 ([#3712](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3712)) ### Added