Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a897a95
Update celery instrumentation to follow semantic conventions
mriamah Aug 25, 2025
0bb7870
Update changelog
mriamah Aug 25, 2025
8dc6ea7
Update celery instrumentation to follow semantic conventions
mriamah Aug 27, 2025
90666fc
Update celery instrumention tests to follow semantic conventions
mriamah Aug 27, 2025
73d3310
Update celery instrumentation to use latest semantic conventions sche…
mriamah Aug 27, 2025
9a33772
Update changelog
mriamah Aug 27, 2025
16e04ef
Merge branch 'main' of github.com:open-telemetry/opentelemetry-python…
mriamah Sep 1, 2025
2a2750e
Merge branch 'main' into semconv-celery
mriamah Sep 7, 2025
717f584
Merge branch 'main' into semconv-celery
mriamah Sep 9, 2025
1a116f9
Merge branch 'main' into semconv-celery
mriamah Sep 16, 2025
ceba850
Merge branch 'main' into semconv-celery
mriamah Sep 21, 2025
97f7109
Merge branch 'main' into semconv-celery
mriamah Oct 4, 2025
11250a8
Merge branch 'main' into semconv-celery
mriamah Oct 19, 2025
c344be7
Add messaging signal type and mode to instrumentations' semantic conv…
mriamah Oct 19, 2025
ce120b8
Update CeleryInstrumentor to use opt-in mode for semantic conventions
mriamah Oct 19, 2025
aef2872
Update celery instrumentation utils to use opt-in mode for new semant…
mriamah Oct 19, 2025
91ebd51
Add test_task_new_sem_conv for testing when opt-in option is messaging
mriamah Oct 19, 2025
a5a51f7
Refactor code
mriamah Oct 19, 2025
93499b1
Merge branch 'main' into semconv-celery
mriamah Nov 1, 2025
d7a3444
Add test for when OTEL_SEMCONV_STABILITY_OPT_IN="messaging/dup" to ha…
mriamah Nov 1, 2025
17a9f5c
Merge branch 'semconv-celery' of github.com:mriamah/opentelemetry-pyt…
mriamah Nov 1, 2025
dd8ebdd
Add back MESSAGING_DESTINATION_KIND use in celery instrumentation for…
mriamah Nov 1, 2025
2c93115
Refactor code
mriamah Nov 1, 2025
cba8dfa
Add back attribute MESSAGING_DESTINATION_KIND to celery instrumentati…
mriamah Nov 1, 2025
da6abc9
Add test for raised exception in celery instrumentation using new sem…
mriamah Nov 1, 2025
06dba64
Update changelog
mriamah Nov 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the review, I will apply your suggestion asap.

Copy link
Author

Choose a reason for hiding this comment

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

Hello @xrmx I applied your suggestion

)

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

Copy link
Author

Choose a reason for hiding this comment

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

Hello @xrmx I applied your suggestion

)
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