Skip to content
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

Use url.rule instead of request.endpoint for span name flask instrumentation #1260

Merged
merged 5 commits into from
Oct 21, 2020
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: 1 addition & 1 deletion docs/getting_started/tests/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def test_flask(self):
output = str(server.stdout.read())
self.assertIn('"name": "HTTP GET"', output)
self.assertIn('"name": "example-request"', output)
self.assertIn('"name": "hello"', output)
self.assertIn('"name": "/"', output)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Use `url.rule` instead of `request.endpoint` for span name
([#1260](https://github.com/open-telemetry/opentelemetry-python/pull/1260))
- Record span status and http.status_code attribute on exception
([#1257](https://github.com/open-telemetry/opentelemetry-python/pull/1257))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ def _before_request():
return

environ = flask.request.environ
span_name = flask.request.endpoint or otel_wsgi.get_default_span_name(
environ
)
span_name = None
try:
span_name = flask.request.url_rule.rule
except AttributeError:
pass
if span_name is None:
span_name = otel_wsgi.get_default_span_name(environ)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a test that exerts this code path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test_404 test covers this.

token = context.attach(
propagators.extract(otel_wsgi.get_header_from_environ, environ)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_simple(self):

span_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(span_list), 1)
self.assertEqual(span_list[0].name, "_hello_endpoint")
self.assertEqual(span_list[0].name, "/hello/<int:helloid>")
self.assertEqual(span_list[0].kind, trace.SpanKind.SERVER)
self.assertEqual(span_list[0].attributes, expected_attrs)

Expand Down Expand Up @@ -154,7 +154,7 @@ def test_internal_error(self):
resp.close()
span_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(span_list), 1)
self.assertEqual(span_list[0].name, "_hello_endpoint")
self.assertEqual(span_list[0].name, "/hello/<int:helloid>")
self.assertEqual(span_list[0].kind, trace.SpanKind.SERVER)
self.assertEqual(span_list[0].attributes, expected_attrs)

Expand Down