Skip to content
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -128,15 +130,15 @@ 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")
meter = get_meter(
__name__,
__version__,
meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
schema_url="https://opentelemetry.io/schemas/1.37.0",
Copy link
Contributor

@xrmx xrmx Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semconvs suggest to make the move to a newer semconv opt-in via OTEL_SEMCONV_STABILITY_OPT_IN, see
https://opentelemetry.io/docs/specs/semconv/messaging/

We have already some tooling in place for handling these in opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py

)

self.create_celery_metrics(meter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes it harder when grepping for the old SpanAttributes module users, please convert the callers from SpanAttributes to messaging_attributes

)
from opentelemetry.trace import Span

if TYPE_CHECKING:
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
},
)
Expand All @@ -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",
},
)

Expand Down Expand Up @@ -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",
},
)
Expand All @@ -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!",
)

Expand All @@ -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",
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down