Skip to content

Commit 67d9843

Browse files
herin049xrmx
andauthored
opentelemetry-instrumentation-pika: remove usage of deprecated SpanAttributes for net attributes (#4068)
* refactor: remove usage of deprecated SpanAttributes for net attributes * update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
1 parent bac99a4 commit 67d9843

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
([#4057](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4057))
5353
- `opentelemetry-instrumentation-cassandra`: Replace SpanAttributes with semconv constants for DB attributes
5454
([#4055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4055))
55+
- `opentelemetry-instrumentation-pika`: Replace SpanAttributes with semconv constants for net attributes
56+
([#4068](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4068))
5557
- `opentelemetry-instrumentation-mysqlclient`: Replace SpanAttributes with semconv constants
5658
([#4067](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4067))
5759

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
from opentelemetry import context, propagate, trace
1313
from opentelemetry.instrumentation.utils import is_instrumentation_enabled
1414
from opentelemetry.propagators.textmap import CarrierT, Getter
15+
from opentelemetry.semconv._incubating.attributes.net_attributes import (
16+
NET_PEER_NAME,
17+
NET_PEER_PORT,
18+
)
1519
from opentelemetry.semconv.trace import (
1620
MessagingOperationValues,
1721
SpanAttributes,
@@ -184,19 +188,11 @@ def _enrich_span(
184188
if not channel:
185189
return
186190
if not hasattr(channel.connection, "params"):
187-
span.set_attribute(
188-
SpanAttributes.NET_PEER_NAME, channel.connection._impl.params.host
189-
)
190-
span.set_attribute(
191-
SpanAttributes.NET_PEER_PORT, channel.connection._impl.params.port
192-
)
191+
span.set_attribute(NET_PEER_NAME, channel.connection._impl.params.host)
192+
span.set_attribute(NET_PEER_PORT, channel.connection._impl.params.port)
193193
else:
194-
span.set_attribute(
195-
SpanAttributes.NET_PEER_NAME, channel.connection.params.host
196-
)
197-
span.set_attribute(
198-
SpanAttributes.NET_PEER_PORT, channel.connection.params.port
199-
)
194+
span.set_attribute(NET_PEER_NAME, channel.connection.params.host)
195+
span.set_attribute(NET_PEER_PORT, channel.connection.params.port)
200196

201197

202198
# pylint:disable=abstract-method

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
from pika.spec import Basic, BasicProperties
2424

2525
from opentelemetry.instrumentation.pika import utils
26+
from opentelemetry.semconv._incubating.attributes.net_attributes import (
27+
NET_PEER_NAME,
28+
NET_PEER_PORT,
29+
)
2630
from opentelemetry.semconv.trace import (
2731
MessagingOperationValues,
2832
SpanAttributes,
@@ -115,11 +119,11 @@ def test_enrich_span_basic_values() -> None:
115119
properties.correlation_id,
116120
),
117121
mock.call(
118-
SpanAttributes.NET_PEER_NAME,
122+
NET_PEER_NAME,
119123
channel.connection.params.host,
120124
),
121125
mock.call(
122-
SpanAttributes.NET_PEER_PORT,
126+
NET_PEER_PORT,
123127
channel.connection.params.port,
124128
),
125129
],
@@ -167,11 +171,11 @@ def test_enrich_span_unique_connection() -> None:
167171
any_order=True,
168172
calls=[
169173
mock.call(
170-
SpanAttributes.NET_PEER_NAME,
174+
NET_PEER_NAME,
171175
channel.connection._impl.params.host,
172176
),
173177
mock.call(
174-
SpanAttributes.NET_PEER_PORT,
178+
NET_PEER_PORT,
175179
channel.connection._impl.params.port,
176180
),
177181
],

0 commit comments

Comments
 (0)