Fix client address is set to server address in new semconv #3354
+19
−8
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.address
in server span is wrongly set to server address.It it because the middleware calls
_set_http_host_server
and theclient.address
is 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_server
later on, since theclient.address
is 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_IN
Span:
The
net.peer.ip
andnet.peer.port
here is correct.With
OTEL_SEMCONV_STABILITY_OPT_IN
Set
os.environ["OTEL_SEMCONV_STABILITY_OPT_IN"] = "http"
and restart the app:Span:
The
client.address
is set to127.0.0.1:8000
, which is the server address.Install patched local version
uv add ../opentelemetry-python-contrib
Span:
The
client.address
is correct now.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.