diff --git a/CHANGELOG.md b/CHANGELOG.md index ebf81ae5b4..14af0182c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,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.37.0 + ([#3712](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3712)) ### Added 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 8a13278b7b..ad070b58b1 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.37.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.37.0", ) self.create_celery_metrics(meter) 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" 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(