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 @@ -60,6 +60,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4068](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4068))
- `opentelemetry-instrumentation-mysqlclient`: Replace SpanAttributes with semconv constants
([#4067](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4067))
- `opentelemetry-instrumentation-pyramid`: Replace SpanAttributes with semconv constants
([#4079](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4079))
- `opentelemetry-instrumentation-tortoiseorm`: Replace SpanAttributes with semconv constants
([#4080](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4080))
- `opentelemetry-instrumentation-asgi`: Replace SpanAttributes with semconv constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
from opentelemetry.instrumentation.pyramid.version import __version__
from opentelemetry.instrumentation.utils import _start_internal_or_server_span
from opentelemetry.metrics import get_meter
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_STATUS_CODE,
)
from opentelemetry.semconv.attributes.http_attributes import HTTP_ROUTE
from opentelemetry.semconv.metrics import MetricInstruments
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.util.http import get_excluded_urls

Expand Down Expand Up @@ -107,9 +110,7 @@ def _before_traversal(event):
if span.is_recording():
attributes = otel_wsgi.collect_request_attributes(request_environ)
if request.matched_route:
attributes[SpanAttributes.HTTP_ROUTE] = (
request.matched_route.pattern
)
attributes[HTTP_ROUTE] = request.matched_route.pattern
for key, value in attributes.items():
span.set_attribute(key, value)
if span.kind == trace.SpanKind.SERVER:
Expand Down Expand Up @@ -206,7 +207,7 @@ def trace_tween(request):
status = getattr(response, "status", status)
status_code = otel_wsgi._parse_status_code(status)
if status_code is not None:
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
duration_attrs[HTTP_STATUS_CODE] = (
otel_wsgi._parse_status_code(status)
)
duration_histogram.record(duration, duration_attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@
set_global_response_propagator,
)
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_FLAVOR,
HTTP_HOST,
HTTP_METHOD,
HTTP_ROUTE,
HTTP_SCHEME,
HTTP_SERVER_NAME,
HTTP_STATUS_CODE,
HTTP_TARGET,
)
from opentelemetry.semconv._incubating.attributes.net_attributes import (
NET_HOST_NAME,
NET_HOST_PORT,
)
from opentelemetry.semconv.attributes import exception_attributes
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.wsgitestutil import WsgiTestBase
from opentelemetry.util.http import get_excluded_urls

Expand All @@ -34,15 +47,15 @@

def expected_attributes(override_attributes):
default_attributes = {
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_SERVER_NAME: "localhost",
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.NET_HOST_NAME: "localhost",
SpanAttributes.HTTP_HOST: "localhost",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.HTTP_FLAVOR: "1.1",
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_METHOD: "GET",
HTTP_SERVER_NAME: "localhost",
HTTP_SCHEME: "http",
NET_HOST_PORT: 80,
NET_HOST_NAME: "localhost",
HTTP_HOST: "localhost",
HTTP_TARGET: "/",
HTTP_FLAVOR: "1.1",
HTTP_STATUS_CODE: 200,
}
for key, val in override_attributes.items():
default_attributes[key] = val
Expand Down Expand Up @@ -97,8 +110,8 @@ def test_uninstrument(self):
def test_simple(self):
expected_attrs = expected_attributes(
{
SpanAttributes.HTTP_TARGET: "/hello/123",
SpanAttributes.HTTP_ROUTE: "/hello/{helloid}",
HTTP_TARGET: "/hello/123",
HTTP_ROUTE: "/hello/{helloid}",
}
)
self.client.get("/hello/123")
Expand Down Expand Up @@ -136,9 +149,9 @@ def test_not_recording(self):
def test_404(self):
expected_attrs = expected_attributes(
{
SpanAttributes.HTTP_METHOD: "POST",
SpanAttributes.HTTP_TARGET: "/bye",
SpanAttributes.HTTP_STATUS_CODE: 404,
HTTP_METHOD: "POST",
HTTP_TARGET: "/bye",
HTTP_STATUS_CODE: 404,
}
)

Expand All @@ -155,9 +168,9 @@ def test_404(self):
def test_internal_error(self):
expected_attrs = expected_attributes(
{
SpanAttributes.HTTP_TARGET: "/hello/500",
SpanAttributes.HTTP_ROUTE: "/hello/{helloid}",
SpanAttributes.HTTP_STATUS_CODE: 500,
HTTP_TARGET: "/hello/500",
HTTP_ROUTE: "/hello/{helloid}",
HTTP_STATUS_CODE: 500,
}
)
resp = self.client.get("/hello/500")
Expand All @@ -184,9 +197,9 @@ def test_internal_error(self):
def test_internal_exception(self):
expected_attrs = expected_attributes(
{
SpanAttributes.HTTP_TARGET: "/hello/900",
SpanAttributes.HTTP_ROUTE: "/hello/{helloid}",
SpanAttributes.HTTP_STATUS_CODE: 500,
HTTP_TARGET: "/hello/900",
HTTP_ROUTE: "/hello/{helloid}",
HTTP_STATUS_CODE: 500,
}
)
with self.assertRaises(NotImplementedError):
Expand Down