Skip to content

Commit

Permalink
HTTP transition for wsgi (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen committed Apr 19, 2024
1 parent 7656bdb commit 2317adc
Show file tree
Hide file tree
Showing 11 changed files with 852 additions and 246 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
- `opentelemetry-sdk-extension-aws` Register AWS resource detectors under the
`opentelemetry_resource_detector` entry point
([#2382](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2382))

### Breaking changes

Expand All @@ -21,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `opentelemetry-sdk-extension-aws` Register AWS resource detectors under the
`opentelemetry_resource_detector` entry point
([#2382](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2382))
- `opentelemetry-instrumentation-wsgi` Implement new semantic convention opt-in with stable http semantic conventions
([#2425](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2425))
- `opentelemetry-instrumentation-threading` Initial release for threading
([#2253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2253))

Expand All @@ -29,6 +31,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-grpc` AioClientInterceptor should propagate with a Metadata object
([#2363](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2363))

### Added

- `opentelemetry-sdk-extension-aws` Register AWS resource detectors under the `opentelemetry_resource_detector` entry point
([#2382](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2382))
- `opentelemetry-instrumentation-wsgi` Implement new semantic convention opt-in with stable http semantic conventions
([#2425](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2425))
- `opentelemetry-instrumentation-threading` Initial release for threading
([#2253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2253))

## Version 1.24.0/0.45b0 (2024-03-28)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
from unittest.mock import Mock, patch

import pytest
from falcon import __version__ as _falcon_verison
from falcon import __version__ as _falcon_version
from falcon import testing
from packaging import version as package_version

from opentelemetry import trace
from opentelemetry.instrumentation._semconv import (
_server_active_requests_count_attrs_old,
_server_duration_attrs_old,
)
from opentelemetry.instrumentation.falcon import FalconInstrumentor
from opentelemetry.instrumentation.propagators import (
TraceResponsePropagator,
get_global_response_propagator,
set_global_response_propagator,
)
from opentelemetry.instrumentation.wsgi import (
_active_requests_count_attrs,
_duration_attrs,
)
from opentelemetry.sdk.metrics.export import (
HistogramDataPoint,
NumberDataPoint,
Expand All @@ -53,8 +53,8 @@
"http.server.duration",
]
_recommended_attrs = {
"http.server.active_requests": _active_requests_count_attrs,
"http.server.duration": _duration_attrs,
"http.server.active_requests": _server_active_requests_count_attrs_old,
"http.server.duration": _server_duration_attrs_old,
}


Expand Down Expand Up @@ -125,7 +125,7 @@ def _test_method(self, method):
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.NET_PEER_PORT: "65133",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
"falcon.resource": "HelloWorldResource",
SpanAttributes.HTTP_STATUS_CODE: 201,
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_404(self):
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.NET_PEER_PORT: "65133",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
SpanAttributes.HTTP_STATUS_CODE: 404,
},
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_500(self):
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.NET_PEER_PORT: "65133",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
SpanAttributes.HTTP_STATUS_CODE: 500,
},
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_url_template(self):
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "falconframework.org",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.NET_PEER_PORT: "65133",
SpanAttributes.NET_PEER_PORT: 65133,
SpanAttributes.HTTP_FLAVOR: "1.1",
"falcon.resource": "UserResource",
SpanAttributes.HTTP_STATUS_CODE: 200,
Expand Down Expand Up @@ -336,6 +336,7 @@ def test_falcon_metric_values(self):
"http.flavor": "1.1",
"http.server_name": "falconframework.org",
"net.host.port": 80,
"net.host.name": "falconframework.org",
"http.status_code": 404,
}
expected_requests_count_attributes = {
Expand All @@ -344,6 +345,8 @@ def test_falcon_metric_values(self):
"http.scheme": "http",
"http.flavor": "1.1",
"http.server_name": "falconframework.org",
"net.host.name": "falconframework.org",
"net.host.port": 80,
}
start = default_timer()
self.client().simulate_get("/hello/756")
Expand Down Expand Up @@ -523,7 +526,7 @@ def test_custom_request_header_not_added_in_internal_span(self):
self.assertNotIn(key, span.attributes)

@pytest.mark.skipif(
condition=package_version.parse(_falcon_verison)
condition=package_version.parse(_falcon_version)
< package_version.parse("2.0.0"),
reason="falcon<2 does not implement custom response headers",
)
Expand Down Expand Up @@ -558,7 +561,7 @@ def test_custom_response_header_added_in_server_span(self):
self.assertNotIn(key, span.attributes)

@pytest.mark.skipif(
condition=package_version.parse(_falcon_verison)
condition=package_version.parse(_falcon_version)
< package_version.parse("2.0.0"),
reason="falcon<2 does not implement custom response headers",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
from flask import Flask, request

from opentelemetry import trace
from opentelemetry.instrumentation._semconv import (
_server_active_requests_count_attrs_old,
_server_duration_attrs_old,
)
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.propagators import (
TraceResponsePropagator,
get_global_response_propagator,
set_global_response_propagator,
)
from opentelemetry.instrumentation.wsgi import (
OpenTelemetryMiddleware,
_active_requests_count_attrs,
_duration_attrs,
)
from opentelemetry.instrumentation.wsgi import OpenTelemetryMiddleware
from opentelemetry.sdk.metrics.export import (
HistogramDataPoint,
NumberDataPoint,
Expand All @@ -54,6 +54,7 @@ def expected_attributes(override_attributes):
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",
Expand All @@ -69,8 +70,8 @@ def expected_attributes(override_attributes):
"http.server.duration",
]
_recommended_attrs = {
"http.server.active_requests": _active_requests_count_attrs,
"http.server.duration": _duration_attrs,
"http.server.active_requests": _server_active_requests_count_attrs_old,
"http.server.duration": _server_duration_attrs_old,
}


Expand Down Expand Up @@ -358,13 +359,16 @@ def test_basic_metric_success(self):
"http.server_name": "localhost",
"net.host.port": 80,
"http.status_code": 200,
"net.host.name": "localhost",
}
expected_requests_count_attributes = {
"http.method": "GET",
"http.host": "localhost",
"http.scheme": "http",
"http.flavor": "1.1",
"http.server_name": "localhost",
"net.host.name": "localhost",
"net.host.port": 80,
}
self._assert_basic_metric(
expected_duration_attributes,
Expand All @@ -374,20 +378,23 @@ def test_basic_metric_success(self):
def test_basic_metric_nonstandard_http_method_success(self):
self.client.open("/hello/756", method="NONSTANDARD")
expected_duration_attributes = {
"http.method": "UNKNOWN",
"http.method": "_OTHER",
"http.host": "localhost",
"http.scheme": "http",
"http.flavor": "1.1",
"http.server_name": "localhost",
"net.host.port": 80,
"http.status_code": 405,
"net.host.name": "localhost",
}
expected_requests_count_attributes = {
"http.method": "UNKNOWN",
"http.method": "_OTHER",
"http.host": "localhost",
"http.scheme": "http",
"http.flavor": "1.1",
"http.server_name": "localhost",
"net.host.name": "localhost",
"net.host.port": 80,
}
self._assert_basic_metric(
expected_duration_attributes,
Expand All @@ -410,13 +417,16 @@ def test_basic_metric_nonstandard_http_method_allowed_success(self):
"http.server_name": "localhost",
"net.host.port": 80,
"http.status_code": 405,
"net.host.name": "localhost",
}
expected_requests_count_attributes = {
"http.method": "NONSTANDARD",
"http.host": "localhost",
"http.scheme": "http",
"http.flavor": "1.1",
"http.server_name": "localhost",
"net.host.name": "localhost",
"net.host.port": 80,
}
self._assert_basic_metric(
expected_duration_attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
from pyramid.config import Configurator

from opentelemetry import trace
from opentelemetry.instrumentation._semconv import (
_server_active_requests_count_attrs_old,
_server_duration_attrs_old,
)
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor
from opentelemetry.sdk.metrics.export import (
HistogramDataPoint,
Expand All @@ -31,8 +35,6 @@
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE,
_active_requests_count_attrs,
_duration_attrs,
)

# pylint: disable=import-error
Expand All @@ -43,8 +45,8 @@
"http.server.duration",
]
_recommended_attrs = {
"http.server.active_requests": _active_requests_count_attrs,
"http.server.duration": _duration_attrs,
"http.server.active_requests": _server_active_requests_count_attrs_old,
"http.server.duration": _server_duration_attrs_old,
}


Expand Down Expand Up @@ -213,13 +215,16 @@ def test_basic_metric_success(self):
"http.server_name": "localhost",
"net.host.port": 80,
"http.status_code": 200,
"net.host.name": "localhost",
}
expected_requests_count_attributes = {
"http.method": "GET",
"http.host": "localhost",
"http.scheme": "http",
"http.flavor": "1.1",
"http.server_name": "localhost",
"net.host.name": "localhost",
"net.host.port": 80,
}
metrics_list = self.memory_metrics_reader.get_metrics_data()
for metric in (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def expected_attributes(override_attributes):
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",
Expand Down
Loading

0 comments on commit 2317adc

Please sign in to comment.