Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -52,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4057](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4057))
- `opentelemetry-instrumentation-cassandra`: Replace SpanAttributes with semconv constants for DB attributes
([#4055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4055))
- `opentelemetry-instrumentation-falcon`: Replace SpanAttributes with semconv constants
([#4066](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4066))
- `opentelemetry-instrumentation-pika`: Replace SpanAttributes with semconv constants for net attributes
([#4068](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4068))
- `opentelemetry-instrumentation-mysqlclient`: Replace SpanAttributes with semconv constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,27 @@
NumberDataPoint,
)
from opentelemetry.sdk.resources import Resource
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_FLAVOR,
HTTP_HOST,
HTTP_METHOD,
HTTP_SCHEME,
HTTP_SERVER_NAME,
HTTP_STATUS_CODE,
HTTP_TARGET,
)
from opentelemetry.semconv._incubating.attributes.net_attributes import (
NET_HOST_PORT,
NET_PEER_IP,
NET_PEER_PORT,
)
from opentelemetry.semconv.attributes.client_attributes import (
CLIENT_PORT,
)
from opentelemetry.semconv.attributes.http_attributes import (
HTTP_REQUEST_METHOD,
HTTP_RESPONSE_STATUS_CODE,
HTTP_ROUTE,
)
from opentelemetry.semconv.attributes.network_attributes import (
NETWORK_PROTOCOL_VERSION,
Expand All @@ -59,7 +74,6 @@
URL_PATH,
URL_SCHEME,
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase
from opentelemetry.test.wsgitestutil import WsgiTestBase
from opentelemetry.trace import StatusCode
Expand Down Expand Up @@ -224,19 +238,17 @@ def _test_method(self, method, old_semconv=True, new_semconv=False):

expected_attributes = {}
expected_attributes_old = {
SpanAttributes.HTTP_METHOD: method,
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/"
if self._has_fixed_http_target
else "/hello",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
HTTP_METHOD: method,
HTTP_SERVER_NAME: "falconframework.org",
HTTP_SCHEME: "http",
NET_HOST_PORT: 80,
HTTP_HOST: "falconframework.org",
HTTP_TARGET: "/" if self._has_fixed_http_target else "/hello",
NET_PEER_PORT: 65133,
HTTP_FLAVOR: "1.1",
"falcon.resource": "HelloWorldResource",
SpanAttributes.HTTP_STATUS_CODE: 201,
SpanAttributes.HTTP_ROUTE: "/hello",
HTTP_STATUS_CODE: 201,
HTTP_ROUTE: "/hello",
}
expected_attributes_new = {
HTTP_REQUEST_METHOD: method,
Expand All @@ -248,7 +260,7 @@ def _test_method(self, method, old_semconv=True, new_semconv=False):
NETWORK_PROTOCOL_VERSION: "1.1",
"falcon.resource": "HelloWorldResource",
HTTP_RESPONSE_STATUS_CODE: 201,
SpanAttributes.HTTP_ROUTE: "/hello",
HTTP_ROUTE: "/hello",
}

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

def test_404(self):
Expand All @@ -276,26 +286,24 @@ def test_404(self):
self.assertSpanHasAttributes(
span,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/"
HTTP_METHOD: "GET",
HTTP_SERVER_NAME: "falconframework.org",
HTTP_SCHEME: "http",
NET_HOST_PORT: 80,
HTTP_HOST: "falconframework.org",
HTTP_TARGET: "/"
if self._has_fixed_http_target
else "/does-not-exist",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
SpanAttributes.HTTP_STATUS_CODE: 404,
NET_PEER_PORT: 65133,
HTTP_FLAVOR: "1.1",
HTTP_STATUS_CODE: 404,
},
)
# In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1
# In falcon>=3, NET_PEER_IP is not set to anything by default
# https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa
if SpanAttributes.NET_PEER_IP in span.attributes:
self.assertEqual(
span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1"
)
if NET_PEER_IP in span.attributes:
self.assertEqual(span.attributes[NET_PEER_IP], "127.0.0.1")

def test_500(self):
try:
Expand All @@ -321,27 +329,23 @@ def test_500(self):
self.assertSpanHasAttributes(
span,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/"
if self._has_fixed_http_target
else "/error",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
SpanAttributes.HTTP_STATUS_CODE: 500,
SpanAttributes.HTTP_ROUTE: "/error",
HTTP_METHOD: "GET",
HTTP_SERVER_NAME: "falconframework.org",
HTTP_SCHEME: "http",
NET_HOST_PORT: 80,
HTTP_HOST: "falconframework.org",
HTTP_TARGET: "/" if self._has_fixed_http_target else "/error",
NET_PEER_PORT: 65133,
HTTP_FLAVOR: "1.1",
HTTP_STATUS_CODE: 500,
HTTP_ROUTE: "/error",
},
)
# In falcon<3, NET_PEER_IP is always set by default to 127.0.0.1
# In falcon>=3, NET_PEER_IP is not set to anything by default
# https://github.com/falconry/falcon/blob/5233d0abed977d9dab78ebadf305f5abe2eef07c/falcon/testing/helpers.py#L1168-L1172 # noqa
if SpanAttributes.NET_PEER_IP in span.attributes:
self.assertEqual(
span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1"
)
if NET_PEER_IP in span.attributes:
self.assertEqual(span.attributes[NET_PEER_IP], "127.0.0.1")

def test_url_template_new_semconv(self):
self.client().simulate_get("/user/123")
Expand Down Expand Up @@ -369,7 +373,7 @@ def test_url_template_new_semconv(self):
NETWORK_PROTOCOL_VERSION: "1.1",
"falcon.resource": "UserResource",
HTTP_RESPONSE_STATUS_CODE: 200,
SpanAttributes.HTTP_ROUTE: "/user/{user_id}",
HTTP_ROUTE: "/user/{user_id}",
},
)

Expand Down Expand Up @@ -398,19 +402,19 @@ def test_url_template(self):
self.assertSpanHasAttributes(
span,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_SERVER_NAME: "falconframework.org",
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/"
HTTP_METHOD: "GET",
HTTP_SERVER_NAME: "falconframework.org",
HTTP_SCHEME: "http",
NET_HOST_PORT: 80,
HTTP_HOST: "falconframework.org",
HTTP_TARGET: "/"
if self._has_fixed_http_target
else "/user/123",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
NET_PEER_PORT: 65133,
HTTP_FLAVOR: "1.1",
"falcon.resource": "UserResource",
SpanAttributes.HTTP_STATUS_CODE: 200,
SpanAttributes.HTTP_ROUTE: "/user/{user_id}",
HTTP_STATUS_CODE: 200,
HTTP_ROUTE: "/user/{user_id}",
},
)

Expand Down