Skip to content

Commit 9dd447a

Browse files
authored
Merge branch 'main' into fix/remove-span-attributes-cassandra
2 parents 058c883 + b8c3794 commit 9dd447a

17 files changed

Lines changed: 938 additions & 158 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
([#3938](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3938))
2828
- `opentelemetry-instrumentation-aiohttp-server`: Support passing `TracerProvider` when instrumenting.
2929
([#3819](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3819))
30+
- `opentelemetry-instrumentation-httpx`: add ability to capture custom headers
31+
([#4047](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4047))
3032

3133
### Fixed
3234

@@ -38,6 +40,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3840
([#4001](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/4001))
3941
- `opentelemetry-instrumentation-psycopg`: Fix `instrument_connection` method to use `_new_cursor_async_factory` on async connections.
4042
([#3956](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3956))
43+
- `opentelemetry-instrumentation-dbapi`: Replace SpanAttributes with semconv constants where applicable
44+
([#4058](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4058))
45+
- `opentelemetry-instrumentation-django`: Replace SpanAttributes with semconv constants where applicable
46+
([#4059](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4059))
47+
- `opentelemetry-instrumentation-celery`: Replace SpanAttributes with semconv constants where applicable
48+
([#4056](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4056))
49+
- `opentelemetry-instrumentation-confluent-kafka`: Replace SpanAttributes with semconv constants where applicable
50+
([#4057](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4057))
4151

4252
## Version 1.39.0/0.60b0 (2025-12-03)
4353

instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
326326
if span.is_recording():
327327
lambda_context = args[1]
328328
# NOTE: The specs mention an exception here, allowing the
329-
# `SpanAttributes.CLOUD_RESOURCE_ID` attribute to be set as a span
329+
# `CLOUD_RESOURCE_ID` attribute to be set as a span
330330
# attribute instead of a resource attribute.
331331
#
332332
# See more:

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def add(x, y):
7676
from opentelemetry.metrics import get_meter
7777
from opentelemetry.propagate import extract, inject
7878
from opentelemetry.propagators.textmap import Getter
79-
from opentelemetry.semconv.trace import SpanAttributes
79+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
80+
MESSAGING_MESSAGE_ID,
81+
)
8082
from opentelemetry.trace.status import Status, StatusCode
8183

8284
if VERSION >= (4, 0, 1):
@@ -240,7 +242,7 @@ def _trace_before_publish(self, *args, **kwargs):
240242
# apply some attributes here because most of the data is not available
241243
if span.is_recording():
242244
span.set_attribute(_TASK_TAG_KEY, _TASK_APPLY_ASYNC)
243-
span.set_attribute(SpanAttributes.MESSAGING_MESSAGE_ID, task_id)
245+
span.set_attribute(MESSAGING_MESSAGE_ID, task_id)
244246
span.set_attribute(_TASK_NAME_KEY, task_name)
245247
utils.set_attributes_from_context(span, kwargs)
246248

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
from celery import registry # pylint: disable=no-name-in-module
2121
from celery.app.task import Task
2222

23+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
24+
MESSAGING_MESSAGE_ID,
25+
)
2326
from opentelemetry.semconv.trace import SpanAttributes
2427
from opentelemetry.trace import Span
2528

@@ -98,7 +101,7 @@ def set_attributes_from_context(span, context):
98101
value = str(value)
99102

100103
elif key == "id":
101-
attribute_name = SpanAttributes.MESSAGING_MESSAGE_ID
104+
attribute_name = MESSAGING_MESSAGE_ID
102105

103106
elif key == "correlation_id":
104107
attribute_name = SpanAttributes.MESSAGING_CONVERSATION_ID

instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@
2020
from opentelemetry import baggage, context
2121
from opentelemetry.instrumentation.celery import CeleryInstrumentor, utils
2222
from opentelemetry.instrumentation.utils import unwrap
23+
from opentelemetry.semconv.attributes.exception_attributes import (
24+
EXCEPTION_MESSAGE,
25+
EXCEPTION_STACKTRACE,
26+
EXCEPTION_TYPE,
27+
)
2328
from opentelemetry.semconv.trace import SpanAttributes
2429
from opentelemetry.test.test_base import TestBase
2530
from opentelemetry.trace import SpanKind, StatusCode
2631

27-
from .celery_test_tasks import app, task_add, task_raises, task_returns_baggage
32+
from .celery_test_tasks import (
33+
CustomError,
34+
app,
35+
task_add,
36+
task_raises,
37+
task_returns_baggage,
38+
)
2839

2940

3041
class TestCeleryInstrumentation(TestBase):
@@ -127,15 +138,15 @@ def test_task_raises(self):
127138
self.assertEqual(1, len(consumer.events))
128139
event = consumer.events[0]
129140

130-
self.assertIn(SpanAttributes.EXCEPTION_STACKTRACE, event.attributes)
141+
self.assertIn(EXCEPTION_STACKTRACE, event.attributes)
131142

132-
# TODO: use plain assertEqual after 1.25 is released (https://github.com/open-telemetry/opentelemetry-python/pull/3837)
133-
self.assertIn(
134-
"CustomError", event.attributes[SpanAttributes.EXCEPTION_TYPE]
143+
self.assertEqual(
144+
f"{CustomError.__module__}.{CustomError.__qualname__}",
145+
event.attributes[EXCEPTION_TYPE],
135146
)
136147

137148
self.assertEqual(
138-
event.attributes[SpanAttributes.EXCEPTION_MESSAGE],
149+
event.attributes[EXCEPTION_MESSAGE],
139150
"The task failed!",
140151
)
141152

instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
from opentelemetry import trace as trace_api
2121
from opentelemetry.instrumentation.celery import utils
2222
from opentelemetry.sdk import trace
23+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
24+
MESSAGING_MESSAGE_ID,
25+
)
2326
from opentelemetry.semconv.trace import SpanAttributes
2427

2528

@@ -47,7 +50,7 @@ def test_set_attributes_from_context(self):
4750
utils.set_attributes_from_context(span, context)
4851

4952
self.assertEqual(
50-
span.attributes.get(SpanAttributes.MESSAGING_MESSAGE_ID),
53+
span.attributes.get(MESSAGING_MESSAGE_ID),
5154
"44b7f305",
5255
)
5356
self.assertEqual(

instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def instrument_consumer(consumer: Consumer, tracer_provider=None)
110110
from opentelemetry import context, propagate, trace
111111
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
112112
from opentelemetry.instrumentation.utils import unwrap
113-
from opentelemetry.semconv.trace import MessagingOperationValues
113+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
114+
MessagingOperationTypeValues,
115+
)
114116
from opentelemetry.trace import Tracer
115117

116118
from .package import _instruments
@@ -363,7 +365,7 @@ def wrap_produce(func, instance, tracer, args, kwargs):
363365
_enrich_span(
364366
span,
365367
topic,
366-
operation=MessagingOperationValues.RECEIVE,
368+
operation=MessagingOperationTypeValues.RECEIVE,
367369
) # Replace
368370
propagate.inject(
369371
headers,
@@ -387,7 +389,7 @@ def wrap_poll(func, instance, tracer, args, kwargs):
387389
record.topic(),
388390
record.partition(),
389391
record.offset(),
390-
operation=MessagingOperationValues.PROCESS,
392+
operation=MessagingOperationTypeValues.PROCESS,
391393
)
392394
instance._current_context_token = context.attach(
393395
trace.set_span_in_context(instance._current_consume_span)
@@ -409,7 +411,7 @@ def wrap_consume(func, instance, tracer, args, kwargs):
409411
_enrich_span(
410412
instance._current_consume_span,
411413
records[0].topic(),
412-
operation=MessagingOperationValues.PROCESS,
414+
operation=MessagingOperationTypeValues.PROCESS,
413415
)
414416

415417
instance._current_context_token = context.attach(

instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33

44
from opentelemetry import context, propagate
55
from opentelemetry.propagators import textmap
6+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
7+
MESSAGING_MESSAGE_ID,
8+
MESSAGING_OPERATION,
9+
MESSAGING_SYSTEM,
10+
MessagingOperationTypeValues,
11+
)
612
from opentelemetry.semconv.trace import (
713
MessagingDestinationKindValues,
8-
MessagingOperationValues,
914
SpanAttributes,
1015
)
1116
from opentelemetry.trace import Link, SpanKind
@@ -115,12 +120,12 @@ def _enrich_span(
115120
topic,
116121
partition: Optional[int] = None,
117122
offset: Optional[int] = None,
118-
operation: Optional[MessagingOperationValues] = None,
123+
operation: Optional[MessagingOperationTypeValues] = None,
119124
):
120125
if not span.is_recording():
121126
return
122127

123-
span.set_attribute(SpanAttributes.MESSAGING_SYSTEM, "kafka")
128+
span.set_attribute(MESSAGING_SYSTEM, "kafka")
124129
span.set_attribute(SpanAttributes.MESSAGING_DESTINATION, topic)
125130

126131
if partition is not None:
@@ -132,15 +137,15 @@ def _enrich_span(
132137
)
133138

134139
if operation:
135-
span.set_attribute(SpanAttributes.MESSAGING_OPERATION, operation.value)
140+
span.set_attribute(MESSAGING_OPERATION, operation.value)
136141
else:
137142
span.set_attribute(SpanAttributes.MESSAGING_TEMP_DESTINATION, True)
138143

139144
# https://stackoverflow.com/questions/65935155/identify-and-find-specific-message-in-kafka-topic
140145
# A message within Kafka is uniquely defined by its topic name, topic partition and offset.
141146
if partition is not None and offset is not None and topic:
142147
span.set_attribute(
143-
SpanAttributes.MESSAGING_MESSAGE_ID,
148+
MESSAGING_MESSAGE_ID,
144149
f"{topic}.{partition}.{offset}",
145150
)
146151

instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/test_instrumentation.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
KafkaContextGetter,
2626
KafkaContextSetter,
2727
)
28+
from opentelemetry.semconv._incubating.attributes.messaging_attributes import (
29+
MESSAGING_MESSAGE_ID,
30+
MESSAGING_OPERATION,
31+
MESSAGING_SYSTEM,
32+
)
2833
from opentelemetry.semconv.trace import (
2934
MessagingDestinationKindValues,
3035
SpanAttributes,
@@ -122,36 +127,36 @@ def test_poll(self) -> None:
122127
{
123128
"name": "topic-10 process",
124129
"attributes": {
125-
SpanAttributes.MESSAGING_OPERATION: "process",
130+
MESSAGING_OPERATION: "process",
126131
SpanAttributes.MESSAGING_KAFKA_PARTITION: 0,
127-
SpanAttributes.MESSAGING_SYSTEM: "kafka",
132+
MESSAGING_SYSTEM: "kafka",
128133
SpanAttributes.MESSAGING_DESTINATION: "topic-10",
129134
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
130-
SpanAttributes.MESSAGING_MESSAGE_ID: "topic-10.0.0",
135+
MESSAGING_MESSAGE_ID: "topic-10.0.0",
131136
},
132137
},
133138
{"name": "recv", "attributes": {}},
134139
{
135140
"name": "topic-20 process",
136141
"attributes": {
137-
SpanAttributes.MESSAGING_OPERATION: "process",
142+
MESSAGING_OPERATION: "process",
138143
SpanAttributes.MESSAGING_KAFKA_PARTITION: 2,
139-
SpanAttributes.MESSAGING_SYSTEM: "kafka",
144+
MESSAGING_SYSTEM: "kafka",
140145
SpanAttributes.MESSAGING_DESTINATION: "topic-20",
141146
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
142-
SpanAttributes.MESSAGING_MESSAGE_ID: "topic-20.2.4",
147+
MESSAGING_MESSAGE_ID: "topic-20.2.4",
143148
},
144149
},
145150
{"name": "recv", "attributes": {}},
146151
{
147152
"name": "topic-30 process",
148153
"attributes": {
149-
SpanAttributes.MESSAGING_OPERATION: "process",
154+
MESSAGING_OPERATION: "process",
150155
SpanAttributes.MESSAGING_KAFKA_PARTITION: 1,
151-
SpanAttributes.MESSAGING_SYSTEM: "kafka",
156+
MESSAGING_SYSTEM: "kafka",
152157
SpanAttributes.MESSAGING_DESTINATION: "topic-30",
153158
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
154-
SpanAttributes.MESSAGING_MESSAGE_ID: "topic-30.1.3",
159+
MESSAGING_MESSAGE_ID: "topic-30.1.3",
155160
},
156161
},
157162
{"name": "recv", "attributes": {}},
@@ -190,8 +195,8 @@ def test_consume(self) -> None:
190195
{
191196
"name": "topic-1 process",
192197
"attributes": {
193-
SpanAttributes.MESSAGING_OPERATION: "process",
194-
SpanAttributes.MESSAGING_SYSTEM: "kafka",
198+
MESSAGING_OPERATION: "process",
199+
MESSAGING_SYSTEM: "kafka",
195200
SpanAttributes.MESSAGING_DESTINATION: "topic-1",
196201
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
197202
},
@@ -200,8 +205,8 @@ def test_consume(self) -> None:
200205
{
201206
"name": "topic-2 process",
202207
"attributes": {
203-
SpanAttributes.MESSAGING_OPERATION: "process",
204-
SpanAttributes.MESSAGING_SYSTEM: "kafka",
208+
MESSAGING_OPERATION: "process",
209+
MESSAGING_SYSTEM: "kafka",
205210
SpanAttributes.MESSAGING_DESTINATION: "topic-2",
206211
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
207212
},
@@ -210,8 +215,8 @@ def test_consume(self) -> None:
210215
{
211216
"name": "topic-3 process",
212217
"attributes": {
213-
SpanAttributes.MESSAGING_OPERATION: "process",
214-
SpanAttributes.MESSAGING_SYSTEM: "kafka",
218+
MESSAGING_OPERATION: "process",
219+
MESSAGING_SYSTEM: "kafka",
215220
SpanAttributes.MESSAGING_DESTINATION: "topic-3",
216221
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
217222
},
@@ -247,12 +252,12 @@ def test_close(self) -> None:
247252
{
248253
"name": "topic-a process",
249254
"attributes": {
250-
SpanAttributes.MESSAGING_OPERATION: "process",
255+
MESSAGING_OPERATION: "process",
251256
SpanAttributes.MESSAGING_KAFKA_PARTITION: 0,
252-
SpanAttributes.MESSAGING_SYSTEM: "kafka",
257+
MESSAGING_SYSTEM: "kafka",
253258
SpanAttributes.MESSAGING_DESTINATION: "topic-a",
254259
SpanAttributes.MESSAGING_DESTINATION_KIND: MessagingDestinationKindValues.QUEUE.value,
255-
SpanAttributes.MESSAGING_MESSAGE_ID: "topic-a.0.0",
260+
MESSAGING_MESSAGE_ID: "topic-a.0.0",
256261
},
257262
},
258263
]

instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,16 @@
184184
is_instrumentation_enabled,
185185
unwrap,
186186
)
187-
from opentelemetry.semconv.trace import SpanAttributes
187+
from opentelemetry.semconv._incubating.attributes.db_attributes import (
188+
DB_NAME,
189+
DB_STATEMENT,
190+
DB_SYSTEM,
191+
DB_USER,
192+
)
193+
from opentelemetry.semconv._incubating.attributes.net_attributes import (
194+
NET_PEER_NAME,
195+
NET_PEER_PORT,
196+
)
188197
from opentelemetry.trace import SpanKind, TracerProvider, get_tracer
189198
from opentelemetry.util._importlib_metadata import version as util_version
190199

@@ -547,13 +556,13 @@ def get_connection_attributes(self, connection: object) -> None:
547556
if user and isinstance(user, bytes):
548557
user = user.decode()
549558
if user is not None:
550-
self.span_attributes[SpanAttributes.DB_USER] = str(user)
559+
self.span_attributes[DB_USER] = str(user)
551560
host = self.connection_props.get("host")
552561
if host is not None:
553-
self.span_attributes[SpanAttributes.NET_PEER_NAME] = host
562+
self.span_attributes[NET_PEER_NAME] = host
554563
port = self.connection_props.get("port")
555564
if port is not None:
556-
self.span_attributes[SpanAttributes.NET_PEER_PORT] = port
565+
self.span_attributes[NET_PEER_PORT] = port
557566

558567

559568
# pylint: disable=abstract-method
@@ -667,13 +676,9 @@ def _populate_span(
667676
if not span.is_recording():
668677
return
669678
statement = self.get_statement(cursor, args)
670-
span.set_attribute(
671-
SpanAttributes.DB_SYSTEM, self._db_api_integration.database_system
672-
)
673-
span.set_attribute(
674-
SpanAttributes.DB_NAME, self._db_api_integration.database
675-
)
676-
span.set_attribute(SpanAttributes.DB_STATEMENT, statement)
679+
span.set_attribute(DB_SYSTEM, self._db_api_integration.database_system)
680+
span.set_attribute(DB_NAME, self._db_api_integration.database)
681+
span.set_attribute(DB_STATEMENT, statement)
677682

678683
for (
679684
attribute_key,

0 commit comments

Comments
 (0)