Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7789448
Fix for FASTAPI unable to record AppService URL
rads-1996 Aug 1, 2025
92e8582
Fixed tests and pylint errors
rads-1996 Aug 1, 2025
06fe0a0
Merge branch 'main' into fix-fastapi-url
rads-1996 Aug 1, 2025
ba85358
Fixed ruff format
rads-1996 Aug 1, 2025
b5a670f
Merge branch 'fix-fastapi-url' of https://github.com/rads-1996/opente…
rads-1996 Aug 1, 2025
81f521a
Updated CHANGELOG
rads-1996 Aug 1, 2025
bd5f31f
Updated CHANGELOG
rads-1996 Aug 4, 2025
c536cb9
Merge branch 'main' into fix-fastapi-url
rads-1996 Aug 6, 2025
7ba7f95
Merge branch 'main' into fix-fastapi-url
rads-1996 Aug 13, 2025
6d58bbc
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
rads-1996 Aug 14, 2025
897a663
Merge branch 'main' into fix-fastapi-url
rads-1996 Aug 19, 2025
1d9ea2e
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
rads-1996 Aug 20, 2025
ba906fe
Addressed feedback
rads-1996 Aug 21, 2025
a2a165d
Merge branch 'fix-fastapi-url' of https://github.com/rads-1996/opente…
rads-1996 Aug 21, 2025
b7f6287
Checking CI runs
rads-1996 Aug 21, 2025
10a24a7
Fix ruff and spellcheck errors
rads-1996 Aug 21, 2025
06302a8
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
rads-1996 Sep 2, 2025
922335c
Fix pytest
rads-1996 Sep 2, 2025
f7f108c
Merge branch 'main' into fix-fastapi-url
emdneto Sep 4, 2025
cb5bb18
Update CHANGELOG.md
xrmx Sep 8, 2025
9713919
Update CHANGELOG.md
xrmx Sep 8, 2025
4886099
Update instrumentation/opentelemetry-instrumentation-asgi/src/opentel…
xrmx Sep 8, 2025
964ec86
Fix ruff
rads-1996 Sep 8, 2025
912f735
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
rads-1996 Sep 8, 2025
ffa529d
Merge branch 'fix-fastapi-url' of https://github.com/rads-1996/opente…
rads-1996 Sep 8, 2025
c96790d
Fix ruff
rads-1996 Sep 8, 2025
ba50468
Updated CHANGELOG
rads-1996 Sep 8, 2025
5e604b9
Merge branch 'main' into fix-fastapi-url
rads-1996 Sep 9, 2025
e31477c
Merge branch 'main' into fix-fastapi-url
rads-1996 Sep 9, 2025
0ab27be
Merge branch 'main' into fix-fastapi-url
xrmx Sep 10, 2025
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
> Use [this search for a list of all CHANGELOG.md files in this repo](https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-python-contrib+path%3A**%2FCHANGELOG.md&type=code).

## Unreleased
- `opentelemetry-instrumentation-asgi` Fixed issue where FastAPI reports IP instead of URL.
([#3670](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3670))

### Fixed

Expand Down Expand Up @@ -44,7 +46,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Version 1.36.0/0.57b0 (2025-07-29)

### Fixed

- `opentelemetry-instrumentation`: Fix dependency conflict detection when instrumented packages are not installed by moving check back to before instrumentors are loaded. Add "instruments-any" feature for instrumentations that target multiple packages.
([#3610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3610))
- infra(ci): Fix git pull failures in core contrib test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,30 @@ def get_host_port_url_tuple(scope):
"""Returns (host, port, full_url) tuple."""
server = scope.get("server") or ["0.0.0.0", 80]
port = server[1]

host_header = asgi_getter.get(scope, "host")
if host_header:
host_value = host_header[0]
# Ensure host_value is a string, not bytes
if isinstance(host_value, bytes):
host_value = _decode_header_item(
host_value
) # use existing function

url_host = host_value

else:
url_host = server[0] + (":" + str(port) if str(port) != "80" else "")
server_host = server[0] + (":" + str(port) if str(port) != "80" else "")

# 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
http_url = scope.get("scheme", "http") + "://" + url_host + full_path
return server_host, port, http_url


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,10 @@ async def test_host_header(self):

def update_expected_server(expected):
expected[3]["attributes"].update(
{SpanAttributes.HTTP_SERVER_NAME: hostname.decode("utf8")}
{
SpanAttributes.HTTP_SERVER_NAME: hostname.decode("utf8"),
SpanAttributes.HTTP_URL: f"http://{hostname.decode('utf8')}/",
}
)
return expected

Expand All @@ -797,7 +800,10 @@ async def test_host_header_both_semconv(self):

def update_expected_server(expected):
expected[3]["attributes"].update(
{SpanAttributes.HTTP_SERVER_NAME: hostname.decode("utf8")}
{
SpanAttributes.HTTP_SERVER_NAME: hostname.decode("utf8"),
SpanAttributes.HTTP_URL: f"http://{hostname.decode('utf8')}/",
}
)
return expected

Expand Down Expand Up @@ -1728,7 +1734,7 @@ def test_request_attributes(self):
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_HOST: "127.0.0.1",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.HTTP_URL: "http://127.0.0.1/?foo=bar",
SpanAttributes.HTTP_URL: "http://test/?foo=bar",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.HTTP_SERVER_NAME: "test",
Expand Down Expand Up @@ -1781,7 +1787,7 @@ def test_request_attributes_both_semconv(self):
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_HOST: "127.0.0.1",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.HTTP_URL: "http://127.0.0.1/?foo=bar",
SpanAttributes.HTTP_URL: "http://test/?foo=bar",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.HTTP_SERVER_NAME: "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def test_templated_route_get(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "GET")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/route/2020/template/",
"http://testserver/route/2020/template/",
)
self.assertEqual(
span.attributes[SpanAttributes.HTTP_ROUTE],
Expand Down Expand Up @@ -219,7 +219,7 @@ async def test_templated_route_get_both_semconv(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "GET")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/route/2020/template/",
"http://testserver/route/2020/template/",
)
self.assertEqual(span.attributes[SpanAttributes.HTTP_SCHEME], "http")
self.assertEqual(span.attributes[SpanAttributes.HTTP_STATUS_CODE], 200)
Expand Down Expand Up @@ -248,7 +248,7 @@ async def test_traced_get(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "GET")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/traced/",
"http://testserver/traced/",
)
self.assertEqual(
span.attributes[SpanAttributes.HTTP_ROUTE], "^traced/"
Expand Down Expand Up @@ -289,7 +289,7 @@ async def test_traced_get_both_semconv(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "GET")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/traced/",
"http://testserver/traced/",
)
self.assertEqual(span.attributes[SpanAttributes.HTTP_SCHEME], "http")
self.assertEqual(span.attributes[SpanAttributes.HTTP_STATUS_CODE], 200)
Expand Down Expand Up @@ -328,7 +328,7 @@ async def test_traced_post(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "POST")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/traced/",
"http://testserver/traced/",
)
self.assertEqual(
span.attributes[SpanAttributes.HTTP_ROUTE], "^traced/"
Expand Down Expand Up @@ -369,7 +369,7 @@ async def test_traced_post_both_semconv(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "POST")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/traced/",
"http://testserver/traced/",
)
self.assertEqual(span.attributes[SpanAttributes.HTTP_SCHEME], "http")
self.assertEqual(span.attributes[SpanAttributes.HTTP_STATUS_CODE], 200)
Expand All @@ -396,7 +396,7 @@ async def test_error(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "GET")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/error/",
"http://testserver/error/",
)
self.assertEqual(span.attributes[SpanAttributes.HTTP_ROUTE], "^error/")
self.assertEqual(span.attributes[SpanAttributes.HTTP_SCHEME], "http")
Expand Down Expand Up @@ -450,7 +450,7 @@ async def test_error_both_semconv(self):
self.assertEqual(span.attributes[SpanAttributes.HTTP_METHOD], "GET")
self.assertEqual(
span.attributes[SpanAttributes.HTTP_URL],
"http://127.0.0.1/error/",
"http://testserver/error/",
)
self.assertEqual(span.attributes[SpanAttributes.HTTP_ROUTE], "^error/")
self.assertEqual(span.attributes[SpanAttributes.HTTP_SCHEME], "http")
Expand Down
Loading