Skip to content

Commit

Permalink
wsgi
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen committed Jul 18, 2024
1 parent bfa3292 commit cd714f9
Show file tree
Hide file tree
Showing 4 changed files with 851 additions and 513 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2580](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2580))
- Populate `{method}` as `HTTP` on `_OTHER` methods from scope for `asgi` middleware
([#2610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2610))
- Populate `{method}` as `HTTP` on `_OTHER` methods from scope for `fastapi` middleware
- Populate `{method}` as `HTTP` on `_OTHER` methods from scope for `fastapi` instrumentation
([#2682](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2682))
- Populate `{method}` as `HTTP` on `_OTHER` methods from scope for `django` middleware
([#2682](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2682))

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def _instrument(self, **kwargs):
)
_DjangoMiddleware._duration_histogram_new = None
if _report_new(sem_conv_opt_in_mode):
self.duration_histogram_new = self.meter.create_histogram(
_DjangoMiddleware._duration_histogram_new = meter.create_histogram(
name=HTTP_SERVER_REQUEST_DURATION,
description="Duration of HTTP server requests.",
unit="s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
get_traced_request_attrs,
normalise_request_header_name,
normalise_response_header_name,
sanitize_method,
)

try:
Expand Down Expand Up @@ -177,17 +178,20 @@ class _DjangoMiddleware(MiddlewareMixin):

@staticmethod
def _get_span_name(request):
method = sanitize_method(request.method.strip())
if method == "_OTHER":
return "HTTP"
try:
if getattr(request, "resolver_match"):
match = request.resolver_match
else:
match = resolve(request.path)

if hasattr(match, "route") and match.route:
return f"{request.method} {match.route}"
return f"{method} {match.route}"

if hasattr(match, "url_name") and match.url_name:
return f"{request.method} {match.url_name}"
return f"{method} {match.url_name}"

return request.method

Expand Down Expand Up @@ -221,7 +225,10 @@ def process_request(self, request):
carrier_getter = wsgi_getter
collect_request_attributes = wsgi_collect_request_attributes

attributes = collect_request_attributes(carrier)
attributes = collect_request_attributes(
carrier,
self._sem_conv_opt_in_mode,
)
span, token = _start_internal_or_server_span(
tracer=self._tracer,
span_name=self._get_span_name(request),
Expand Down
Loading

0 comments on commit cd714f9

Please sign in to comment.