Skip to content

Commit dc7abae

Browse files
Merge branch 'main' into pika-selectconnection-support
2 parents 337a4a2 + 0a03c9a commit dc7abae

File tree

9 files changed

+184
-117
lines changed

9 files changed

+184
-117
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
## Version 1.34.0/0.55b0 (2025-06-04)
2020

21+
### Fixed
22+
23+
- `opentelemetry-resource-detector-containerid`: make it more quiet on platforms without cgroups
24+
([#3579](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3579))
25+
2126
### Added
2227

2328
- `opentelemetry-instrumentation-aiokafka` Add instrumentation of `consumer.getmany` (batch)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def serve():
149149
grpc_client_instrumentor.instrument()
150150
151151
async def run():
152-
with grpc.aio.insecure_channel("localhost:50051") as channel:
152+
async with grpc.aio.insecure_channel("localhost:50051") as channel:
153153
154154
stub = helloworld_pb2_grpc.GreeterStub(channel)
155155
response = await stub.SayHello(helloworld_pb2.HelloRequest(name="YOU"))
@@ -168,7 +168,7 @@ async def run():
168168
169169
from opentelemetry.instrumentation.grpc import aio_client_interceptors
170170
171-
channel = grpc.aio.insecure_channel("localhost:12345", interceptors=aio_client_interceptors())
171+
async with grpc.aio.insecure_channel("localhost:50051", interceptors=aio_client_interceptors()) as channel:
172172
173173
174174
Usage Aio Server
@@ -253,6 +253,11 @@ async def serve():
253253
254254
.. code-block::
255255
256+
import grpc
257+
from concurrent import futures
258+
from opentelemetry.instrumentation.grpc import filters
259+
from opentelemetry.instrumentation.grpc import server_interceptor
260+
256261
my_interceptor = server_interceptor(
257262
filter_ = filters.negate(filters.method_name("TestMethod"))
258263
)

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@
6565
from pyramid.config import Configurator
6666
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor
6767
68-
settings = {
69-
'pyramid.tweens', 'opentelemetry.instrumentation.pyramid.trace_tween_factory\\nyour_tween_no_1\\nyour_tween_no_2',
70-
}
71-
config = Configurator(settings=settings)
68+
config = Configurator()
69+
config.add_tween('opentelemetry.instrumentation.pyramid.trace_tween_factory')
7270
PyramidInstrumentor().instrument_config(config)
7371
7472
# use your config as normal.

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,19 @@ def client_response_hook(span, future):
182182
from opentelemetry.metrics import get_meter
183183
from opentelemetry.metrics._internal.instrument import Histogram
184184
from opentelemetry.propagators import textmap
185+
from opentelemetry.semconv._incubating.attributes.http_attributes import (
186+
HTTP_CLIENT_IP,
187+
HTTP_FLAVOR,
188+
HTTP_HOST,
189+
HTTP_METHOD,
190+
HTTP_SCHEME,
191+
HTTP_STATUS_CODE,
192+
HTTP_TARGET,
193+
)
194+
from opentelemetry.semconv._incubating.attributes.net_attributes import (
195+
NET_PEER_IP,
196+
)
185197
from opentelemetry.semconv.metrics import MetricInstruments
186-
from opentelemetry.semconv.trace import SpanAttributes
187198
from opentelemetry.trace.status import Status, StatusCode
188199
from opentelemetry.util.http import (
189200
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST,
@@ -442,23 +453,21 @@ def _collect_custom_response_headers_attributes(response_headers):
442453

443454
def _get_attributes_from_request(request):
444455
attrs = {
445-
SpanAttributes.HTTP_METHOD: request.method,
446-
SpanAttributes.HTTP_SCHEME: request.protocol,
447-
SpanAttributes.HTTP_HOST: request.host,
448-
SpanAttributes.HTTP_TARGET: request.path,
456+
HTTP_METHOD: request.method,
457+
HTTP_SCHEME: request.protocol,
458+
HTTP_HOST: request.host,
459+
HTTP_TARGET: request.path,
449460
}
450461

451462
if request.remote_ip:
452463
# NET_PEER_IP is the address of the network peer
453464
# HTTP_CLIENT_IP is the address of the client, which might be different
454465
# if Tornado is set to trust X-Forwarded-For headers (xheaders=True)
455-
attrs[SpanAttributes.HTTP_CLIENT_IP] = request.remote_ip
466+
attrs[HTTP_CLIENT_IP] = request.remote_ip
456467
if hasattr(request.connection, "context") and getattr(
457468
request.connection.context, "_orig_remote_ip", None
458469
):
459-
attrs[SpanAttributes.NET_PEER_IP] = (
460-
request.connection.context._orig_remote_ip
461-
)
470+
attrs[NET_PEER_IP] = request.connection.context._orig_remote_ip
462471

463472
return extract_attributes_from_object(
464473
request, _traced_request_attrs, attrs
@@ -550,7 +559,7 @@ def _finish_span(tracer, handler, error=None):
550559
return
551560

552561
if ctx.span.is_recording():
553-
ctx.span.set_attribute(SpanAttributes.HTTP_STATUS_CODE, status_code)
562+
ctx.span.set_attribute(HTTP_STATUS_CODE, status_code)
554563
otel_status_code = http_status_to_status_code(
555564
status_code, server_span=True
556565
)
@@ -601,7 +610,7 @@ def _record_on_finish_metrics(server_histograms, handler, error=None):
601610
metric_attributes = _create_metric_attributes(handler)
602611

603612
if isinstance(error, tornado.web.HTTPError):
604-
metric_attributes[SpanAttributes.HTTP_STATUS_CODE] = error.status_code
613+
metric_attributes[HTTP_STATUS_CODE] = error.status_code
605614

606615
server_histograms[MetricInstruments.HTTP_SERVER_RESPONSE_SIZE].record(
607616
response_size, attributes=metric_attributes
@@ -621,18 +630,18 @@ def _record_on_finish_metrics(server_histograms, handler, error=None):
621630

622631
def _create_active_requests_attributes(request):
623632
metric_attributes = {
624-
SpanAttributes.HTTP_METHOD: request.method,
625-
SpanAttributes.HTTP_SCHEME: request.protocol,
626-
SpanAttributes.HTTP_FLAVOR: request.version,
627-
SpanAttributes.HTTP_HOST: request.host,
628-
SpanAttributes.HTTP_TARGET: request.path,
633+
HTTP_METHOD: request.method,
634+
HTTP_SCHEME: request.protocol,
635+
HTTP_FLAVOR: request.version,
636+
HTTP_HOST: request.host,
637+
HTTP_TARGET: request.path,
629638
}
630639

631640
return metric_attributes
632641

633642

634643
def _create_metric_attributes(handler):
635644
metric_attributes = _create_active_requests_attributes(handler.request)
636-
metric_attributes[SpanAttributes.HTTP_STATUS_CODE] = handler.get_status()
645+
metric_attributes[HTTP_STATUS_CODE] = handler.get_status()
637646

638647
return metric_attributes

instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
from opentelemetry import trace
2121
from opentelemetry.instrumentation.utils import http_status_to_status_code
2222
from opentelemetry.propagate import inject
23-
from opentelemetry.semconv.trace import SpanAttributes
23+
from opentelemetry.semconv._incubating.attributes.http_attributes import (
24+
HTTP_METHOD,
25+
HTTP_STATUS_CODE,
26+
HTTP_URL,
27+
)
2428
from opentelemetry.trace.status import Status, StatusCode
2529
from opentelemetry.util.http import remove_url_credentials
2630

@@ -75,8 +79,8 @@ def fetch_async(
7579

7680
if span.is_recording():
7781
attributes = {
78-
SpanAttributes.HTTP_URL: remove_url_credentials(request.url),
79-
SpanAttributes.HTTP_METHOD: request.method,
82+
HTTP_URL: remove_url_credentials(request.url),
83+
HTTP_METHOD: request.method,
8084
}
8185
for key, value in attributes.items():
8286
span.set_attribute(key, value)
@@ -135,7 +139,7 @@ def _finish_tracing_callback(
135139
)
136140

137141
if status_code is not None:
138-
span.set_attribute(SpanAttributes.HTTP_STATUS_CODE, status_code)
142+
span.set_attribute(HTTP_STATUS_CODE, status_code)
139143
span.set_status(status)
140144

141145
if response is not None:
@@ -160,9 +164,9 @@ def _finish_tracing_callback(
160164

161165
def _create_metric_attributes(response):
162166
metric_attributes = {
163-
SpanAttributes.HTTP_STATUS_CODE: response.code,
164-
SpanAttributes.HTTP_URL: remove_url_credentials(response.request.url),
165-
SpanAttributes.HTTP_METHOD: response.request.method,
167+
HTTP_STATUS_CODE: response.code,
168+
HTTP_URL: remove_url_credentials(response.request.url),
169+
HTTP_METHOD: response.request.method,
166170
}
167171

168172
return metric_attributes

0 commit comments

Comments
 (0)