-
Notifications
You must be signed in to change notification settings - Fork 798
add OTEL_PYTHON_HTTP_SERVER_REQUEST_DURATION_SERVER_ATTRIBUTES_ENABLED flag #2597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeitlinger
wants to merge
12
commits into
open-telemetry:main
Choose a base branch
from
zeitlinger:http-metrics-server-arributes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e5d7fd
add OTEL_ENABLE_SERVER_ATTRIBUTES_FOR_REQUEST_DURATION flag to add se…
zeitlinger 885d0a5
add changelog
zeitlinger fdcd334
explicit parameter
zeitlinger 935b64f
pr review
zeitlinger e7e9b65
changelog
zeitlinger e024655
pr review
zeitlinger f02358e
try out to store state in the instrumentation
zeitlinger 36373e4
pr review
zeitlinger 4237917
pr review
zeitlinger c7da9e5
fix dependencies
zeitlinger fdb35ba
Merge branch 'main' into http-metrics-server-arributes
xrmx adae750
Merge branch 'main' into http-metrics-server-arributes
emdneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
|
||
from opentelemetry import trace | ||
from opentelemetry.instrumentation._semconv import ( | ||
OTEL_PYTHON_HTTP_SERVER_ACTIVE_REQUESTS_COUNT_SERVER_ATTRIBUTES_ENABLED, | ||
OTEL_PYTHON_HTTP_SERVER_REQUEST_DURATION_SERVER_ATTRIBUTES_ENABLED, | ||
OTEL_SEMCONV_STABILITY_OPT_IN, | ||
_OpenTelemetrySemanticConventionStability, | ||
_server_active_requests_count_attrs_new, | ||
|
@@ -514,22 +516,25 @@ def test_flask_metrics_new_semconv(self): | |
self.assertTrue(len(scope_metric.metrics) != 0) | ||
for metric in scope_metric.metrics: | ||
self.assertIn(metric.name, _expected_metric_names_new) | ||
data_points = list(metric.data.data_points) | ||
self.assertEqual(len(data_points), 1) | ||
for point in data_points: | ||
if isinstance(point, HistogramDataPoint): | ||
self.assertEqual(point.count, 3) | ||
self.assertAlmostEqual( | ||
duration_s, point.sum, places=2 | ||
) | ||
histogram_data_point_seen = True | ||
if isinstance(point, NumberDataPoint): | ||
number_data_point_seen = True | ||
for attr in point.attributes: | ||
self.assertIn( | ||
attr, | ||
_recommended_metrics_attrs_new[metric.name], | ||
) | ||
with self.subTest(metric=metric.name): | ||
data_points = list(metric.data.data_points) | ||
self.assertEqual(len(data_points), 1) | ||
for point in data_points: | ||
if isinstance(point, HistogramDataPoint): | ||
self.assertEqual(point.count, 3) | ||
self.assertAlmostEqual( | ||
duration_s, point.sum, places=2 | ||
) | ||
histogram_data_point_seen = True | ||
if isinstance(point, NumberDataPoint): | ||
number_data_point_seen = True | ||
for attr in point.attributes: | ||
self.assertIn( | ||
attr, | ||
_recommended_metrics_attrs_new[ | ||
metric.name | ||
], | ||
) | ||
self.assertTrue(number_data_point_seen and histogram_data_point_seen) | ||
|
||
def test_flask_metric_values(self): | ||
|
@@ -615,6 +620,35 @@ def test_basic_metric_success_new_semconv(self): | |
expected_requests_count_attributes, | ||
) | ||
|
||
@patch.dict( | ||
"os.environ", | ||
{ | ||
OTEL_PYTHON_HTTP_SERVER_REQUEST_DURATION_SERVER_ATTRIBUTES_ENABLED: "1", | ||
OTEL_PYTHON_HTTP_SERVER_ACTIVE_REQUESTS_COUNT_SERVER_ATTRIBUTES_ENABLED: "1", | ||
}, | ||
) | ||
def test_basic_metric_success_new_semconv_server_address(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you be able to add tests for django, asgi and wsgi as well? |
||
self.client.get("/hello/756") | ||
expected_duration_attributes = { | ||
"http.request.method": "GET", | ||
"url.scheme": "http", | ||
"http.route": "/hello/<int:helloid>", | ||
"network.protocol.version": "1.1", | ||
"http.response.status_code": 200, | ||
"server.address": "localhost", | ||
"server.port": 80, | ||
} | ||
expected_requests_count_attributes = { | ||
"http.request.method": "GET", | ||
"url.scheme": "http", | ||
"server.address": "localhost", | ||
"server.port": 80, | ||
} | ||
self._assert_basic_metric( | ||
expected_duration_attributes, | ||
expected_requests_count_attributes, | ||
) | ||
|
||
def test_basic_metric_nonstandard_http_method_success(self): | ||
self.client.open("/hello/756", method="NONSTANDARD") | ||
expected_duration_attributes = { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.