Skip to content

Commit db66531

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

2 files changed

Lines changed: 64 additions & 58 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-falcon`: Replace SpanAttributes with semconv constants
56+
([#4066](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4066))
5557
- `opentelemetry-instrumentation-pika`: Replace SpanAttributes with semconv constants for net attributes
5658
([#4068](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4068))
5759
- `opentelemetry-instrumentation-mysqlclient`: Replace SpanAttributes with semconv constants

instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,27 @@
4141
NumberDataPoint,
4242
)
4343
from opentelemetry.sdk.resources import Resource
44+
from opentelemetry.semconv._incubating.attributes.http_attributes import (
45+
HTTP_FLAVOR,
46+
HTTP_HOST,
47+
HTTP_METHOD,
48+
HTTP_SCHEME,
49+
HTTP_SERVER_NAME,
50+
HTTP_STATUS_CODE,
51+
HTTP_TARGET,
52+
)
53+
from opentelemetry.semconv._incubating.attributes.net_attributes import (
54+
NET_HOST_PORT,
55+
NET_PEER_IP,
56+
NET_PEER_PORT,
57+
)
4458
from opentelemetry.semconv.attributes.client_attributes import (
4559
CLIENT_PORT,
4660
)
4761
from opentelemetry.semconv.attributes.http_attributes import (
4862
HTTP_REQUEST_METHOD,
4963
HTTP_RESPONSE_STATUS_CODE,
64+
HTTP_ROUTE,
5065
)
5166
from opentelemetry.semconv.attributes.network_attributes import (
5267
NETWORK_PROTOCOL_VERSION,
@@ -59,7 +74,6 @@
5974
URL_PATH,
6075
URL_SCHEME,
6176
)
62-
from opentelemetry.semconv.trace import SpanAttributes
6377
from opentelemetry.test.test_base import TestBase
6478
from opentelemetry.test.wsgitestutil import WsgiTestBase
6579
from opentelemetry.trace import StatusCode
@@ -224,19 +238,17 @@ def _test_method(self, method, old_semconv=True, new_semconv=False):
224238

225239
expected_attributes = {}
226240
expected_attributes_old = {
227-
SpanAttributes.HTTP_METHOD: method,
228-
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
229-
SpanAttributes.HTTP_SCHEME: "http",
230-
SpanAttributes.NET_HOST_PORT: 80,
231-
SpanAttributes.HTTP_HOST: "falconframework.org",
232-
SpanAttributes.HTTP_TARGET: "/"
233-
if self._has_fixed_http_target
234-
else "/hello",
235-
SpanAttributes.NET_PEER_PORT: 65133,
236-
SpanAttributes.HTTP_FLAVOR: "1.1",
241+
HTTP_METHOD: method,
242+
HTTP_SERVER_NAME: "falconframework.org",
243+
HTTP_SCHEME: "http",
244+
NET_HOST_PORT: 80,
245+
HTTP_HOST: "falconframework.org",
246+
HTTP_TARGET: "/" if self._has_fixed_http_target else "/hello",
247+
NET_PEER_PORT: 65133,
248+
HTTP_FLAVOR: "1.1",
237249
"falcon.resource": "HelloWorldResource",
238-
SpanAttributes.HTTP_STATUS_CODE: 201,
239-
SpanAttributes.HTTP_ROUTE: "/hello",
250+
HTTP_STATUS_CODE: 201,
251+
HTTP_ROUTE: "/hello",
240252
}
241253
expected_attributes_new = {
242254
HTTP_REQUEST_METHOD: method,
@@ -248,7 +260,7 @@ def _test_method(self, method, old_semconv=True, new_semconv=False):
248260
NETWORK_PROTOCOL_VERSION: "1.1",
249261
"falcon.resource": "HelloWorldResource",
250262
HTTP_RESPONSE_STATUS_CODE: 201,
251-
SpanAttributes.HTTP_ROUTE: "/hello",
263+
HTTP_ROUTE: "/hello",
252264
}
253265

254266
if old_semconv:
@@ -260,10 +272,8 @@ def _test_method(self, method, old_semconv=True, new_semconv=False):
260272
# In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1
261273
# In falcon>=3, NET_PEER_IP is not set to anything by default
262274
# https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa
263-
if SpanAttributes.NET_PEER_IP in span.attributes:
264-
self.assertEqual(
265-
span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1"
266-
)
275+
if NET_PEER_IP in span.attributes:
276+
self.assertEqual(span.attributes[NET_PEER_IP], "127.0.0.1")
267277
self.memory_exporter.clear()
268278

269279
def test_404(self):
@@ -276,26 +286,24 @@ def test_404(self):
276286
self.assertSpanHasAttributes(
277287
span,
278288
{
279-
SpanAttributes.HTTP_METHOD: "GET",
280-
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
281-
SpanAttributes.HTTP_SCHEME: "http",
282-
SpanAttributes.NET_HOST_PORT: 80,
283-
SpanAttributes.HTTP_HOST: "falconframework.org",
284-
SpanAttributes.HTTP_TARGET: "/"
289+
HTTP_METHOD: "GET",
290+
HTTP_SERVER_NAME: "falconframework.org",
291+
HTTP_SCHEME: "http",
292+
NET_HOST_PORT: 80,
293+
HTTP_HOST: "falconframework.org",
294+
HTTP_TARGET: "/"
285295
if self._has_fixed_http_target
286296
else "/does-not-exist",
287-
SpanAttributes.NET_PEER_PORT: 65133,
288-
SpanAttributes.HTTP_FLAVOR: "1.1",
289-
SpanAttributes.HTTP_STATUS_CODE: 404,
297+
NET_PEER_PORT: 65133,
298+
HTTP_FLAVOR: "1.1",
299+
HTTP_STATUS_CODE: 404,
290300
},
291301
)
292302
# In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1
293303
# In falcon>=3, NET_PEER_IP is not set to anything by default
294304
# https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa
295-
if SpanAttributes.NET_PEER_IP in span.attributes:
296-
self.assertEqual(
297-
span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1"
298-
)
305+
if NET_PEER_IP in span.attributes:
306+
self.assertEqual(span.attributes[NET_PEER_IP], "127.0.0.1")
299307

300308
def test_500(self):
301309
try:
@@ -321,27 +329,23 @@ def test_500(self):
321329
self.assertSpanHasAttributes(
322330
span,
323331
{
324-
SpanAttributes.HTTP_METHOD: "GET",
325-
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
326-
SpanAttributes.HTTP_SCHEME: "http",
327-
SpanAttributes.NET_HOST_PORT: 80,
328-
SpanAttributes.HTTP_HOST: "falconframework.org",
329-
SpanAttributes.HTTP_TARGET: "/"
330-
if self._has_fixed_http_target
331-
else "/error",
332-
SpanAttributes.NET_PEER_PORT: 65133,
333-
SpanAttributes.HTTP_FLAVOR: "1.1",
334-
SpanAttributes.HTTP_STATUS_CODE: 500,
335-
SpanAttributes.HTTP_ROUTE: "/error",
332+
HTTP_METHOD: "GET",
333+
HTTP_SERVER_NAME: "falconframework.org",
334+
HTTP_SCHEME: "http",
335+
NET_HOST_PORT: 80,
336+
HTTP_HOST: "falconframework.org",
337+
HTTP_TARGET: "/" if self._has_fixed_http_target else "/error",
338+
NET_PEER_PORT: 65133,
339+
HTTP_FLAVOR: "1.1",
340+
HTTP_STATUS_CODE: 500,
341+
HTTP_ROUTE: "/error",
336342
},
337343
)
338344
# In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1
339345
# In falcon>=3, NET_PEER_IP is not set to anything by default
340346
# https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa
341-
if SpanAttributes.NET_PEER_IP in span.attributes:
342-
self.assertEqual(
343-
span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1"
344-
)
347+
if NET_PEER_IP in span.attributes:
348+
self.assertEqual(span.attributes[NET_PEER_IP], "127.0.0.1")
345349

346350
def test_url_template_new_semconv(self):
347351
self.client().simulate_get("/user/123")
@@ -369,7 +373,7 @@ def test_url_template_new_semconv(self):
369373
NETWORK_PROTOCOL_VERSION: "1.1",
370374
"falcon.resource": "UserResource",
371375
HTTP_RESPONSE_STATUS_CODE: 200,
372-
SpanAttributes.HTTP_ROUTE: "/user/{user_id}",
376+
HTTP_ROUTE: "/user/{user_id}",
373377
},
374378
)
375379

@@ -398,19 +402,19 @@ def test_url_template(self):
398402
self.assertSpanHasAttributes(
399403
span,
400404
{
401-
SpanAttributes.HTTP_METHOD: "GET",
402-
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
403-
SpanAttributes.HTTP_SCHEME: "http",
404-
SpanAttributes.NET_HOST_PORT: 80,
405-
SpanAttributes.HTTP_HOST: "falconframework.org",
406-
SpanAttributes.HTTP_TARGET: "/"
405+
HTTP_METHOD: "GET",
406+
HTTP_SERVER_NAME: "falconframework.org",
407+
HTTP_SCHEME: "http",
408+
NET_HOST_PORT: 80,
409+
HTTP_HOST: "falconframework.org",
410+
HTTP_TARGET: "/"
407411
if self._has_fixed_http_target
408412
else "/user/123",
409-
SpanAttributes.NET_PEER_PORT: 65133,
410-
SpanAttributes.HTTP_FLAVOR: "1.1",
413+
NET_PEER_PORT: 65133,
414+
HTTP_FLAVOR: "1.1",
411415
"falcon.resource": "UserResource",
412-
SpanAttributes.HTTP_STATUS_CODE: 200,
413-
SpanAttributes.HTTP_ROUTE: "/user/{user_id}",
416+
HTTP_STATUS_CODE: 200,
417+
HTTP_ROUTE: "/user/{user_id}",
414418
},
415419
)
416420

0 commit comments

Comments
 (0)