Skip to content

Commit

Permalink
Bugfix django instrumentation (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhutianyu authored Nov 2, 2020
1 parent 8b60879 commit a3a75e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Django instrumentation is now enabled by default but can be disabled by setting `OTEL_PYTHON_DJANGO_INSTRUMENT` to `False` ([#1239](https://github.com/open-telemetry/opentelemetry-python/pull/1239))
- Bugfix use request.path replace request.get_full_path(). It will get correct span name ([#1309](https://github.com/open-telemetry/opentelemetry-python/pull/1309#))

## Version 0.14b0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _get_span_name(request):
if getattr(request, "resolver_match"):
match = request.resolver_match
else:
match = resolve(request.get_full_path())
match = resolve(request.path)

if hasattr(match, "route"):
return match.route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def test_exclude_lists(self):
self.assertEqual(len(span_list), 1)

def test_span_name(self):
# test no query_string
Client().get("/span_name/1234/")
span_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(span_list), 1)
Expand All @@ -262,6 +263,22 @@ def test_span_name(self):
else "tests.views.route_span_name",
)

def test_span_name_for_query_string(self):
"""
request not have query string
"""
Client().get("/span_name/1234/?query=test")
span_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(span_list), 1)

span = span_list[0]
self.assertEqual(
span.name,
"^span_name/([0-9]{4})/$"
if DJANGO_2_2
else "tests.views.route_span_name",
)

def test_span_name_404(self):
Client().get("/span_name/1234567890/")
span_list = self.memory_exporter.get_finished_spans()
Expand Down

0 comments on commit a3a75e3

Please sign in to comment.