-
Notifications
You must be signed in to change notification settings - Fork 703
feat(wsgi): low cardinality span name and name override #837
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1d4a264
WSGI: Changed default span-name, added callback to change span-name.
Skeen f6b551c
Merge remote-tracking branch 'upstream/master' into ticket/409_low_ca…
Skeen b29eb1a
Merge remote-tracking branch 'upstream/master' into majorgreys/pr440
majorgreys 804d4a4
use default function
majorgreys 18bde06
update flask and pyramid
majorgreys f15652d
lint fix
majorgreys 84b2057
handle empty request method
majorgreys 583a8fa
Merge branch 'master' into majorgreys/pr440
majorgreys a5016ee
Update ext/opentelemetry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py
majorgreys c1ce80a
handle int server port
majorgreys 8e4584c
fix lint
majorgreys c60f32a
assume port is string
majorgreys 8a7a208
Merge branch 'master' into majorgreys/pr440
majorgreys 2daedb0
Merge branch 'master' into majorgreys/pr440
majorgreys 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 |
---|---|---|
|
@@ -74,7 +74,9 @@ def error_wsgi(environ, start_response): | |
|
||
|
||
class TestWsgiApplication(WsgiTestBase): | ||
def validate_response(self, response, error=None): | ||
def validate_response( | ||
self, response, error=None, span_name="HTTP GET", http_method="GET" | ||
): | ||
while True: | ||
try: | ||
value = next(response) | ||
|
@@ -95,23 +97,22 @@ def validate_response(self, response, error=None): | |
|
||
span_list = self.memory_exporter.get_finished_spans() | ||
self.assertEqual(len(span_list), 1) | ||
self.assertEqual(span_list[0].name, "/") | ||
self.assertEqual(span_list[0].name, span_name) | ||
self.assertEqual(span_list[0].kind, trace_api.SpanKind.SERVER) | ||
self.assertEqual( | ||
span_list[0].attributes, | ||
{ | ||
"component": "http", | ||
"http.method": "GET", | ||
"http.server_name": "127.0.0.1", | ||
"http.scheme": "http", | ||
"host.port": 80, | ||
"http.host": "127.0.0.1", | ||
"http.flavor": "1.0", | ||
"http.url": "http://127.0.0.1/", | ||
"http.status_text": "OK", | ||
"http.status_code": 200, | ||
}, | ||
) | ||
expected_attributes = { | ||
"component": "http", | ||
"http.server_name": "127.0.0.1", | ||
"http.scheme": "http", | ||
"host.port": 80, | ||
"http.host": "127.0.0.1", | ||
"http.flavor": "1.0", | ||
"http.url": "http://127.0.0.1/", | ||
"http.status_text": "OK", | ||
"http.status_code": 200, | ||
} | ||
if http_method is not None: | ||
expected_attributes["http.method"] = http_method | ||
self.assertEqual(span_list[0].attributes, expected_attributes) | ||
|
||
def test_basic_wsgi_call(self): | ||
app = otel_wsgi.OpenTelemetryMiddleware(simple_wsgi) | ||
|
@@ -147,6 +148,27 @@ def test_wsgi_exc_info(self): | |
response = app(self.environ, self.start_response) | ||
self.validate_response(response, error=ValueError) | ||
|
||
def test_override_span_name(self): | ||
"""Test that span_names can be overwritten by our callback function.""" | ||
span_name = "Dymaxion" | ||
|
||
def get_predefined_span_name(scope): | ||
# pylint: disable=unused-argument | ||
return span_name | ||
Comment on lines
+155
to
+157
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. Nit: this could be replaced with a In [4]: from unittest.mock import Mock
In [5]: the_mock = Mock(**{"return_value": "Dymaxion"})
In [6]: the_mock({"a": "b"})
Out[6]: 'Dymaxion' |
||
|
||
app = otel_wsgi.OpenTelemetryMiddleware( | ||
simple_wsgi, name_callback=get_predefined_span_name | ||
) | ||
response = app(self.environ, self.start_response) | ||
self.validate_response(response, span_name=span_name) | ||
|
||
def test_default_span_name_missing_request_method(self): | ||
"""Test that default span_names with missing request method.""" | ||
self.environ.pop("REQUEST_METHOD") | ||
app = otel_wsgi.OpenTelemetryMiddleware(simple_wsgi) | ||
response = app(self.environ, self.start_response) | ||
self.validate_response(response, span_name="HTTP", http_method=None) | ||
|
||
|
||
class TestWsgiAttributes(unittest.TestCase): | ||
def setUp(self): | ||
|
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.