Skip to content

Commit 556b0cf

Browse files
authored
Merge branch 'main' into fix/openai-v2-version
2 parents 130eb63 + af17965 commit 556b0cf

File tree

5 files changed

+69
-12
lines changed
  • instrumentation
    • opentelemetry-instrumentation-asgi/tests
    • opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore
    • opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging
  • opentelemetry-instrumentation/src/opentelemetry/instrumentation

5 files changed

+69
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
1212
## Unreleased
1313

14+
### Fixed
15+
16+
- `opentelemetry-instrumentation` Fix client address is set to server address in new semconv
17+
([#3354](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3354))
18+
1419
## Version 1.31.0/0.52b0 (2025-03-12)
1520

1621
### Added
@@ -36,7 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3641
- Loosen `opentelemetry-instrumentation-starlette[instruments]` specifier
3742
([#3304](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3304))
3843

39-
4044
### Fixed
4145

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

114118
- `opentelemetry-exporter-prometheus-remote-write` updated protobuf required version from 4.21 to 5.26 and regenerated protobufs
115-
([#3219](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3219))
119+
([#3219](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3219))
116120
- `opentelemetry-instrumentation-sqlalchemy` including sqlcomment in `db.statement` span attribute value is now opt-in
117121
([#3112](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3112))
118122
- `opentelemetry-instrumentation-dbapi` including sqlcomment in `db.statement` span attribute value is now opt-in

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252
from opentelemetry.semconv.attributes.network_attributes import (
5353
NETWORK_PROTOCOL_VERSION,
5454
)
55-
from opentelemetry.semconv.attributes.server_attributes import SERVER_PORT
55+
from opentelemetry.semconv.attributes.server_attributes import (
56+
SERVER_ADDRESS,
57+
SERVER_PORT,
58+
)
5659
from opentelemetry.semconv.attributes.url_attributes import (
5760
URL_PATH,
5861
URL_QUERY,
@@ -401,6 +404,7 @@ def validate_outputs(
401404
"attributes": {
402405
HTTP_REQUEST_METHOD: "GET",
403406
URL_SCHEME: "http",
407+
SERVER_ADDRESS: "127.0.0.1",
404408
SERVER_PORT: 80,
405409
NETWORK_PROTOCOL_VERSION: "1.0",
406410
URL_PATH: "/",
@@ -436,6 +440,7 @@ def validate_outputs(
436440
"attributes": {
437441
HTTP_REQUEST_METHOD: "GET",
438442
URL_SCHEME: "http",
443+
SERVER_ADDRESS: "127.0.0.1",
439444
SERVER_PORT: 80,
440445
NETWORK_PROTOCOL_VERSION: "1.0",
441446
URL_PATH: "/",
@@ -706,7 +711,7 @@ async def test_behavior_with_scope_server_as_none_new_semconv(self):
706711
def update_expected_server(expected):
707712
expected[3]["attributes"].update(
708713
{
709-
CLIENT_ADDRESS: "0.0.0.0",
714+
SERVER_ADDRESS: "0.0.0.0",
710715
SERVER_PORT: 80,
711716
}
712717
)
@@ -733,7 +738,7 @@ def update_expected_server(expected):
733738
SpanAttributes.HTTP_HOST: "0.0.0.0",
734739
SpanAttributes.NET_HOST_PORT: 80,
735740
SpanAttributes.HTTP_URL: "http://0.0.0.0/",
736-
CLIENT_ADDRESS: "0.0.0.0",
741+
SERVER_ADDRESS: "0.0.0.0",
737742
SERVER_PORT: 80,
738743
}
739744
)
@@ -948,7 +953,7 @@ async def test_websocket(self):
948953
SpanAttributes.HTTP_HOST: self.scope["server"][0],
949954
SpanAttributes.HTTP_FLAVOR: self.scope["http_version"],
950955
SpanAttributes.HTTP_TARGET: self.scope["path"],
951-
SpanAttributes.HTTP_URL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
956+
SpanAttributes.HTTP_URL: f"{self.scope['scheme']}://{self.scope['server'][0]}{self.scope['path']}",
952957
SpanAttributes.NET_PEER_IP: self.scope["client"][0],
953958
SpanAttributes.NET_PEER_PORT: self.scope["client"][1],
954959
SpanAttributes.HTTP_STATUS_CODE: 200,
@@ -1018,6 +1023,7 @@ async def test_websocket_new_semconv(self):
10181023
"kind": trace_api.SpanKind.SERVER,
10191024
"attributes": {
10201025
URL_SCHEME: self.scope["scheme"],
1026+
SERVER_ADDRESS: self.scope["server"][0],
10211027
SERVER_PORT: self.scope["server"][1],
10221028
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
10231029
URL_PATH: self.scope["path"],
@@ -1096,12 +1102,13 @@ async def test_websocket_both_semconv(self):
10961102
SpanAttributes.HTTP_HOST: self.scope["server"][0],
10971103
SpanAttributes.HTTP_FLAVOR: self.scope["http_version"],
10981104
SpanAttributes.HTTP_TARGET: self.scope["path"],
1099-
SpanAttributes.HTTP_URL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
1105+
SpanAttributes.HTTP_URL: f"{self.scope['scheme']}://{self.scope['server'][0]}{self.scope['path']}",
11001106
SpanAttributes.NET_PEER_IP: self.scope["client"][0],
11011107
SpanAttributes.NET_PEER_PORT: self.scope["client"][1],
11021108
SpanAttributes.HTTP_STATUS_CODE: 200,
11031109
SpanAttributes.HTTP_METHOD: self.scope["method"],
11041110
URL_SCHEME: self.scope["scheme"],
1111+
SERVER_ADDRESS: self.scope["server"][0],
11051112
SERVER_PORT: self.scope["server"][1],
11061113
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
11071114
URL_PATH: self.scope["path"],
@@ -1661,6 +1668,7 @@ def test_request_attributes_new_semconv(self):
16611668
HTTP_REQUEST_METHOD: "GET",
16621669
URL_PATH: "/",
16631670
URL_QUERY: "foo=bar",
1671+
SERVER_ADDRESS: "127.0.0.1",
16641672
SERVER_PORT: 80,
16651673
URL_SCHEME: "http",
16661674
NETWORK_PROTOCOL_VERSION: "1.0",
@@ -1696,6 +1704,7 @@ def test_request_attributes_both_semconv(self):
16961704
HTTP_REQUEST_METHOD: "GET",
16971705
URL_PATH: "/",
16981706
URL_QUERY: "foo=bar",
1707+
SERVER_ADDRESS: "127.0.0.1",
16991708
SERVER_PORT: 80,
17001709
URL_SCHEME: "http",
17011710
NETWORK_PROTOCOL_VERSION: "1.0",

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
.. code:: python
2929
3030
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
31-
import botocore
31+
import botocore.session
3232
3333
3434
# Instrument Botocore
@@ -39,7 +39,7 @@
3939
session.set_credentials(
4040
access_key="access-key", secret_key="secret-key"
4141
)
42-
ec2 = self.session.create_client("ec2", region_name="us-west-2")
42+
ec2 = session.create_client("ec2", region_name="us-west-2")
4343
ec2.describe_instances()
4444
4545
API
@@ -58,13 +58,15 @@
5858
.. code: python
5959
6060
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
61-
import botocore
61+
import botocore.session
6262
6363
def request_hook(span, service_name, operation_name, api_params):
6464
# request hook logic
65+
pass
6566
6667
def response_hook(span, service_name, operation_name, result):
6768
# response hook logic
69+
pass
6870
6971
# Instrument Botocore with hooks
7072
BotocoreInstrumentor().instrument(request_hook=request_hook, response_hook=response_hook)
@@ -74,7 +76,7 @@ def response_hook(span, service_name, operation_name, result):
7476
session.set_credentials(
7577
access_key="access-key", secret_key="secret-key"
7678
)
77-
ec2 = self.session.create_client("ec2", region_name="us-west-2")
79+
ec2 = session.create_client("ec2", region_name="us-west-2")
7880
ec2.describe_instances()
7981
8082
Extensions

instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,47 @@
1414

1515
# pylint: disable=empty-docstring,no-value-for-parameter,no-member,no-name-in-module
1616

17+
"""
18+
The OpenTelemetry `logging` integration automatically injects tracing context into
19+
log statements, though it is opt-in and must be enabled explicitly by setting the
20+
environment variable `OTEL_PYTHON_LOG_CORRELATION` to `true`.
21+
22+
.. code-block:: python
23+
24+
import logging
25+
26+
from opentelemetry.instrumentation.logging import LoggingInstrumentor
27+
28+
LoggingInstrumentor().instrument()
29+
30+
logging.warning('OTel test')
31+
32+
When running the above example you will see the following output:
33+
34+
::
35+
36+
2025-03-05 09:40:04,398 WARNING [root] [example.py:7] [trace_id=0 span_id=0 resource.service.name= trace_sampled=False] - OTel test
37+
38+
The environment variable `OTEL_PYTHON_LOG_CORRELATION` must be set to `true`
39+
in order to enable trace context injection into logs by calling
40+
`logging.basicConfig()` and setting a logging format that makes use of the
41+
injected tracing variables.
42+
43+
Alternatively, `set_logging_format` argument can be set to `True` when
44+
initializing the `LoggingInstrumentor` class to achieve the same effect:
45+
46+
.. code-block:: python
47+
48+
import logging
49+
50+
from opentelemetry.instrumentation.logging import LoggingInstrumentor
51+
52+
LoggingInstrumentor().instrument(set_logging_format=True)
53+
54+
logging.warning('OTel test')
55+
56+
"""
57+
1758
import logging # pylint: disable=import-self
1859
from os import environ
1960
from typing import Collection

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_semconv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ def _set_http_host_server(result, host, sem_conv_opt_in_mode):
354354
if _report_old(sem_conv_opt_in_mode):
355355
set_string_attribute(result, SpanAttributes.HTTP_HOST, host)
356356
if _report_new(sem_conv_opt_in_mode):
357-
set_string_attribute(result, CLIENT_ADDRESS, host)
357+
if not result.get(SERVER_ADDRESS):
358+
set_string_attribute(result, SERVER_ADDRESS, host)
358359

359360

360361
# net.peer.ip -> net.sock.peer.addr

0 commit comments

Comments
 (0)