Skip to content

Commit

Permalink
fix(opentelemetry-instrumentation-asgi): Correct http.url attribute g…
Browse files Browse the repository at this point in the history
…eneration (#2477)
  • Loading branch information
dhofstetter authored Jul 3, 2024
1 parent b16394b commit ef4bc9f
Show file tree
Hide file tree
Showing 6 changed files with 907 additions and 424 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2612](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2612))
- `opentelemetry-instrumentation-system-metrics` Permit to use psutil 6.0+.
([#2630](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2630))
- `opentelemetry-instrumentation-asgi` Fix generation of `http.target` and `http.url` attributes for ASGI apps
using sub apps
([#2477](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2477))


### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,13 @@ def get_host_port_url_tuple(scope):
server = scope.get("server") or ["0.0.0.0", 80]
port = server[1]
server_host = server[0] + (":" + str(port) if str(port) != "80" else "")
full_path = scope.get("root_path", "") + scope.get("path", "")
# using the scope path is enough, see:
# - https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope (see: root_path and path)
# - https://asgi.readthedocs.io/en/latest/specs/www.html#wsgi-compatibility (see: PATH_INFO)
# PATH_INFO can be derived by stripping root_path from path
# -> that means that the path should contain the root_path already, so prefixing it again is not necessary
# - https://wsgi.readthedocs.io/en/latest/definitions.html#envvar-PATH_INFO
full_path = scope.get("path", "")
http_url = scope.get("scheme", "http") + "://" + server_host + full_path
return server_host, port, http_url

Expand Down
Loading

0 comments on commit ef4bc9f

Please sign in to comment.