Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix client address is set to server address in new semconv #3354

Merged
merged 8 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- `opentelemetry-instrumentation` Fix client address is set to server address in new semconv
([#3354](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3354))

### Added

- `opentelemetry-instrumentation-openai-v2` Update doc for OpenAI Instrumentation to support OpenAI Compatible Platforms
Expand All @@ -34,7 +37,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Loosen `opentelemetry-instrumentation-starlette[instruments]` specifier
([#3304](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3304))


### Fixed

- `opentelemetry-instrumentation-redis` Add missing entry in doc string for `def _instrument`
Expand Down Expand Up @@ -108,7 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Breaking changes

- `opentelemetry-exporter-prometheus-remote-write` updated protobuf required version from 4.21 to 5.26 and regenerated protobufs
([#3219](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3219))
([#3219](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3219))
- `opentelemetry-instrumentation-sqlalchemy` including sqlcomment in `db.statement` span attribute value is now opt-in
([#3112](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3112))
- `opentelemetry-instrumentation-dbapi` including sqlcomment in `db.statement` span attribute value is now opt-in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
from opentelemetry.semconv.attributes.network_attributes import (
NETWORK_PROTOCOL_VERSION,
)
from opentelemetry.semconv.attributes.server_attributes import SERVER_PORT
from opentelemetry.semconv.attributes.server_attributes import (
SERVER_ADDRESS,
SERVER_PORT,
)
from opentelemetry.semconv.attributes.url_attributes import (
URL_PATH,
URL_QUERY,
Expand Down Expand Up @@ -401,6 +404,7 @@ def validate_outputs(
"attributes": {
HTTP_REQUEST_METHOD: "GET",
URL_SCHEME: "http",
SERVER_ADDRESS: "127.0.0.1",
SERVER_PORT: 80,
NETWORK_PROTOCOL_VERSION: "1.0",
URL_PATH: "/",
Expand Down Expand Up @@ -436,6 +440,7 @@ def validate_outputs(
"attributes": {
HTTP_REQUEST_METHOD: "GET",
URL_SCHEME: "http",
SERVER_ADDRESS: "127.0.0.1",
SERVER_PORT: 80,
NETWORK_PROTOCOL_VERSION: "1.0",
URL_PATH: "/",
Expand Down Expand Up @@ -706,7 +711,7 @@ async def test_behavior_with_scope_server_as_none_new_semconv(self):
def update_expected_server(expected):
expected[3]["attributes"].update(
{
CLIENT_ADDRESS: "0.0.0.0",
SERVER_ADDRESS: "0.0.0.0",
SERVER_PORT: 80,
}
)
Expand All @@ -733,7 +738,7 @@ def update_expected_server(expected):
SpanAttributes.HTTP_HOST: "0.0.0.0",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_URL: "http://0.0.0.0/",
CLIENT_ADDRESS: "0.0.0.0",
SERVER_ADDRESS: "0.0.0.0",
SERVER_PORT: 80,
}
)
Expand Down Expand Up @@ -948,7 +953,7 @@ async def test_websocket(self):
SpanAttributes.HTTP_HOST: self.scope["server"][0],
SpanAttributes.HTTP_FLAVOR: self.scope["http_version"],
SpanAttributes.HTTP_TARGET: self.scope["path"],
SpanAttributes.HTTP_URL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
SpanAttributes.HTTP_URL: f"{self.scope['scheme']}://{self.scope['server'][0]}{self.scope['path']}",
SpanAttributes.NET_PEER_IP: self.scope["client"][0],
SpanAttributes.NET_PEER_PORT: self.scope["client"][1],
SpanAttributes.HTTP_STATUS_CODE: 200,
Expand Down Expand Up @@ -1018,6 +1023,7 @@ async def test_websocket_new_semconv(self):
"kind": trace_api.SpanKind.SERVER,
"attributes": {
URL_SCHEME: self.scope["scheme"],
SERVER_ADDRESS: self.scope["server"][0],
SERVER_PORT: self.scope["server"][1],
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
URL_PATH: self.scope["path"],
Expand Down Expand Up @@ -1096,12 +1102,13 @@ async def test_websocket_both_semconv(self):
SpanAttributes.HTTP_HOST: self.scope["server"][0],
SpanAttributes.HTTP_FLAVOR: self.scope["http_version"],
SpanAttributes.HTTP_TARGET: self.scope["path"],
SpanAttributes.HTTP_URL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
SpanAttributes.HTTP_URL: f"{self.scope['scheme']}://{self.scope['server'][0]}{self.scope['path']}",
SpanAttributes.NET_PEER_IP: self.scope["client"][0],
SpanAttributes.NET_PEER_PORT: self.scope["client"][1],
SpanAttributes.HTTP_STATUS_CODE: 200,
SpanAttributes.HTTP_METHOD: self.scope["method"],
URL_SCHEME: self.scope["scheme"],
SERVER_ADDRESS: self.scope["server"][0],
SERVER_PORT: self.scope["server"][1],
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
URL_PATH: self.scope["path"],
Expand Down Expand Up @@ -1661,6 +1668,7 @@ def test_request_attributes_new_semconv(self):
HTTP_REQUEST_METHOD: "GET",
URL_PATH: "/",
URL_QUERY: "foo=bar",
SERVER_ADDRESS: "127.0.0.1",
SERVER_PORT: 80,
URL_SCHEME: "http",
NETWORK_PROTOCOL_VERSION: "1.0",
Expand Down Expand Up @@ -1696,6 +1704,7 @@ def test_request_attributes_both_semconv(self):
HTTP_REQUEST_METHOD: "GET",
URL_PATH: "/",
URL_QUERY: "foo=bar",
SERVER_ADDRESS: "127.0.0.1",
SERVER_PORT: 80,
URL_SCHEME: "http",
NETWORK_PROTOCOL_VERSION: "1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _set_http_host_server(result, host, sem_conv_opt_in_mode):
if _report_old(sem_conv_opt_in_mode):
set_string_attribute(result, SpanAttributes.HTTP_HOST, host)
if _report_new(sem_conv_opt_in_mode):
set_string_attribute(result, CLIENT_ADDRESS, host)
set_string_attribute(result, SERVER_ADDRESS, host)


# net.peer.ip -> net.sock.peer.addr
Expand Down