You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix client address is set to server address in new semconv - #3354
y-young
changed the title
Fix client address is set to server address when semconv stability is opted in
Fix client address is set to server address in new semconv
Mar 11, 2025
I remember discussing #2814 with @lzchen and there was a good reason for that. Will try to remember the details
I can't remember the reasoning for having http.host map to client.address, this was not properly defined in the migration guide. The deprecation notice says: Deprecated, use one of server.address, client.addressorhttp.request.header.host instead, depending on the usage.
I remember discussing #2814 with @lzchen and there was a good reason for that. Will try to remember the details
I can't remember the reasoning for having http.host map to client.address, this was not properly defined in the migration guide. The deprecation notice says: Deprecated, use one of server.address, client.addressorhttp.request.header.host instead, depending on the usage.
I remember the deprecation notice; that's why I thought it made sense. Thanks @lzchen for the double-check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With
OTEL_SEMCONV_STABILITY_OPT_IN=http, theclient.addressin server span is wrongly set to server address.It it because the middleware calls
_set_http_host_serverand theclient.addressis set for the first time to server address here:opentelemetry-python-contrib/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py
Line 357 in 3708604
When it calls
_set_http_peer_ip_serverlater on, since theclient.addressis already set, this has no effect:opentelemetry-python-contrib/opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py
Lines 368 to 371 in 3708604
This was changed in #2814.
Fixes #3356.
Type of change
How Has This Been Tested?
Tested with a minimal FastAPI application: https://github.com/y-young/opentelemetry-fastapi-test
Without patch
Without
OTEL_SEMCONV_STABILITY_OPT_INSpan:
{ "name": "GET /", "context": { "trace_id": "0x3d94c2edf94a8c68e66a261883939a70", "span_id": "0x26a8e38e79afe0ae", "trace_state": "[]" }, "kind": "SpanKind.SERVER", "parent_id": null, "start_time": "2025-03-11T14:42:33.575716Z", "end_time": "2025-03-11T14:42:33.582507Z", "status": { "status_code": "UNSET" }, "attributes": { "http.scheme": "http", "http.host": "127.0.0.1:8000", "net.host.port": 8000, "http.flavor": "1.1", "http.target": "/", "http.url": "http://127.0.0.1:8000/", "http.method": "GET", "http.server_name": "127.0.0.1:8000", "http.user_agent": "", "net.peer.ip": "127.0.0.1", "net.peer.port": 54737, "http.route": "/", "http.status_code": 200 }, "events": [], "links": [], "resource": { "attributes": { "service.name": "test-app" }, "schema_url": "" } }The
net.peer.ipandnet.peer.porthere is correct.With
OTEL_SEMCONV_STABILITY_OPT_INSet
os.environ["OTEL_SEMCONV_STABILITY_OPT_IN"] = "http"and restart the app:Span:
{ "name": "GET /", "context": { "trace_id": "0xc37fa0f9c920df31a3f6966771f70ce4", "span_id": "0x8799fdefa09e60b1", "trace_state": "[]" }, "kind": "SpanKind.SERVER", "parent_id": null, "start_time": "2025-03-11T14:39:09.180212Z", "end_time": "2025-03-11T14:39:09.185639Z", "status": { "status_code": "UNSET" }, "attributes": { "url.scheme": "http", "client.address": "127.0.0.1:8000", "server.port": 8000, "network.protocol.version": "1.1", "url.path": "/", "http.request.method": "GET", "user_agent.original": "", "client.port": 50644, "http.route": "/", "http.response.status_code": 200 }, "events": [], "links": [], "resource": { "attributes": { "service.name": "test-app" }, "schema_url": "" } }The
client.addressis set to127.0.0.1:8000, which is the server address.Install patched local version
uv add ../opentelemetry-python-contribSpan:
{ "name": "GET /", "context": { "trace_id": "0xc669651b2543f96d4abc362360ff76da", "span_id": "0x79ed73755c5bee36", "trace_state": "[]" }, "kind": "SpanKind.SERVER", "parent_id": null, "start_time": "2025-03-11T14:33:58.230421Z", "end_time": "2025-03-11T14:33:58.236676Z", "status": { "status_code": "UNSET" }, "attributes": { "url.scheme": "http", "server.address": "127.0.0.1:8000", "server.port": 8000, "network.protocol.version": "1.1", "url.path": "/", "http.request.method": "GET", "user_agent.original": "", "client.address": "127.0.0.1", "client.port": 62487, "http.route": "/", "http.response.status_code": 200 }, "events": [], "links": [], "resource": { "attributes": { "service.name": "test-app" }, "schema_url": "" } }The
client.addressis correct now.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.