Skip to content

Commit 0c60d34

Browse files
authored
Merge branch 'main' into feature/asyncio-instrumentation
2 parents bcf3172 + 7c12ad9 commit 0c60d34

File tree

32 files changed

+199
-306
lines changed

32 files changed

+199
-306
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
([#2002](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2002))
2121
- `opentelemetry-instrument-grpc` Fix arity of context.abort for AIO RPCs
2222
([#2066](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2066))
23+
- Consolidate instrumentation suppression mechanisms and fix bug in httpx instrumentation
24+
([#2061](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2061))
2325

2426
### Fixed
2527

28+
- `opentelemetry-instrumentation-httpx` Remove URL credentials
29+
([#2020](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2020))
2630
- `opentelemetry-instrumentation-urllib`/`opentelemetry-instrumentation-urllib3` Fix metric descriptions to match semantic conventions
2731
([#1959](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1959))
32+
- `opentelemetry-resource-detector-azure` Added dependency for Cloud Resource ID attribute
33+
([#2072](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2072))
2834

2935
## Version 1.21.0/0.42b0 (2023-11-01)
3036

instrumentation/opentelemetry-instrumentation-aio-pika/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ classifiers = [
2626
]
2727
dependencies = [
2828
"opentelemetry-api ~= 1.5",
29+
"opentelemetry-instrumentation == 0.44b0.dev",
2930
"wrapt >= 1.0.0, < 2.0.0",
3031
]
3132

instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/callback_decorator.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
from opentelemetry import context, propagate, trace
2020
from opentelemetry.instrumentation.aio_pika.span_builder import SpanBuilder
21-
from opentelemetry.instrumentation.aio_pika.utils import (
22-
is_instrumentation_enabled,
23-
)
21+
from opentelemetry.instrumentation.utils import is_instrumentation_enabled
2422
from opentelemetry.semconv.trace import MessagingOperationValues
2523
from opentelemetry.trace import Span, Tracer
2624

instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/span_builder.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
from aio_pika.abc import AbstractChannel, AbstractMessage
1717

18-
from opentelemetry.instrumentation.aio_pika.utils import (
19-
is_instrumentation_enabled,
20-
)
18+
from opentelemetry.instrumentation.utils import is_instrumentation_enabled
2119
from opentelemetry.semconv.trace import (
2220
MessagingOperationValues,
2321
SpanAttributes,

instrumentation/opentelemetry-instrumentation-aio-pika/src/opentelemetry/instrumentation/aio_pika/utils.py

-9
This file was deleted.

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def response_hook(span: Span, params: typing.Union[
9494
from opentelemetry.instrumentation.aiohttp_client.version import __version__
9595
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
9696
from opentelemetry.instrumentation.utils import (
97-
_SUPPRESS_INSTRUMENTATION_KEY,
9897
http_status_to_status_code,
98+
is_instrumentation_enabled,
9999
unwrap,
100100
)
101101
from opentelemetry.propagate import inject
@@ -179,7 +179,7 @@ async def on_request_start(
179179
trace_config_ctx: types.SimpleNamespace,
180180
params: aiohttp.TraceRequestStartParams,
181181
):
182-
if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY):
182+
if not is_instrumentation_enabled():
183183
trace_config_ctx.span = None
184184
return
185185

@@ -282,7 +282,7 @@ def _instrument(
282282

283283
# pylint:disable=unused-argument
284284
def instrumented_init(wrapped, instance, args, kwargs):
285-
if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY):
285+
if not is_instrumentation_enabled():
286286
return wrapped(*args, **kwargs)
287287

288288
client_trace_configs = list(kwargs.get("trace_configs") or [])

instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
from http_server_mock import HttpServerMock
2828
from pkg_resources import iter_entry_points
2929

30-
from opentelemetry import context
3130
from opentelemetry import trace as trace_api
3231
from opentelemetry.instrumentation import aiohttp_client
3332
from opentelemetry.instrumentation.aiohttp_client import (
3433
AioHttpClientInstrumentor,
3534
)
36-
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
35+
from opentelemetry.instrumentation.utils import suppress_instrumentation
3736
from opentelemetry.semconv.trace import SpanAttributes
3837
from opentelemetry.test.test_base import TestBase
3938
from opentelemetry.trace import Span, StatusCode
@@ -512,25 +511,17 @@ async def uninstrument_request(server: aiohttp.test_utils.TestServer):
512511
self.assert_spans(1)
513512

514513
def test_suppress_instrumentation(self):
515-
token = context.attach(
516-
context.set_value(_SUPPRESS_INSTRUMENTATION_KEY, True)
517-
)
518-
try:
514+
with suppress_instrumentation():
519515
run_with_test_server(
520516
self.get_default_request(), self.URL, self.default_handler
521517
)
522-
finally:
523-
context.detach(token)
524518
self.assert_spans(0)
525519

526520
@staticmethod
527521
async def suppressed_request(server: aiohttp.test_utils.TestServer):
528522
async with aiohttp.test_utils.TestClient(server) as client:
529-
token = context.attach(
530-
context.set_value(_SUPPRESS_INSTRUMENTATION_KEY, True)
531-
)
532-
await client.get(TestAioHttpClientInstrumentor.URL)
533-
context.detach(token)
523+
with suppress_instrumentation():
524+
await client.get(TestAioHttpClientInstrumentor.URL)
534525

535526
def test_suppress_instrumentation_after_creation(self):
536527
run_with_test_server(

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from opentelemetry import context, propagate, trace
3939
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
4040
from opentelemetry.instrumentation.utils import (
41-
_SUPPRESS_INSTRUMENTATION_KEY,
41+
is_instrumentation_enabled,
4242
unwrap,
4343
)
4444
from opentelemetry.propagators.textmap import CarrierT, Getter, Setter
@@ -218,7 +218,7 @@ def _create_processing_span(
218218

219219
def _wrap_send_message(self, sqs_class: type) -> None:
220220
def send_wrapper(wrapped, instance, args, kwargs):
221-
if context.get_value(_SUPPRESS_INSTRUMENTATION_KEY):
221+
if not is_instrumentation_enabled():
222222
return wrapped(*args, **kwargs)
223223
queue_url = kwargs.get("QueueUrl")
224224
# The method expect QueueUrl and Entries params, so if they are None, we call wrapped to receive the
@@ -252,7 +252,7 @@ def send_batch_wrapper(wrapped, instance, args, kwargs):
252252
# The method expect QueueUrl and Entries params, so if they are None, we call wrapped to receive the
253253
# original exception
254254
if (
255-
context.get_value(_SUPPRESS_INSTRUMENTATION_KEY)
255+
not is_instrumentation_enabled()
256256
or not queue_url
257257
or not entries
258258
):

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

+14-22
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ def response_hook(span, service_name, operation_name, result):
8686
from botocore.exceptions import ClientError
8787
from wrapt import wrap_function_wrapper
8888

89-
from opentelemetry import context as context_api
90-
91-
# FIXME: fix the importing of this private attribute when the location of the _SUPPRESS_HTTP_INSTRUMENTATION_KEY is defined.
92-
from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY
9389
from opentelemetry.instrumentation.botocore.extensions import _find_extension
9490
from opentelemetry.instrumentation.botocore.extensions.types import (
9591
_AwsSdkCallContext,
@@ -98,7 +94,8 @@ def response_hook(span, service_name, operation_name, result):
9894
from opentelemetry.instrumentation.botocore.version import __version__
9995
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
10096
from opentelemetry.instrumentation.utils import (
101-
_SUPPRESS_INSTRUMENTATION_KEY,
97+
is_instrumentation_enabled,
98+
suppress_http_instrumentation,
10299
unwrap,
103100
)
104101
from opentelemetry.propagators.aws.aws_xray_propagator import AwsXRayPropagator
@@ -171,7 +168,7 @@ def _patched_endpoint_prepare_request(
171168

172169
# pylint: disable=too-many-branches
173170
def _patched_api_call(self, original_func, instance, args, kwargs):
174-
if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY):
171+
if not is_instrumentation_enabled():
175172
return original_func(*args, **kwargs)
176173

177174
call_context = _determine_call_context(instance, args)
@@ -200,25 +197,20 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
200197
_safe_invoke(extension.before_service_call, span)
201198
self._call_request_hook(span, call_context)
202199

203-
token = context_api.attach(
204-
context_api.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True)
205-
)
206-
207-
result = None
208200
try:
209-
result = original_func(*args, **kwargs)
210-
except ClientError as error:
211-
result = getattr(error, "response", None)
212-
_apply_response_attributes(span, result)
213-
_safe_invoke(extension.on_error, span, error)
214-
raise
215-
else:
216-
_apply_response_attributes(span, result)
217-
_safe_invoke(extension.on_success, span, result)
201+
with suppress_http_instrumentation():
202+
result = None
203+
try:
204+
result = original_func(*args, **kwargs)
205+
except ClientError as error:
206+
result = getattr(error, "response", None)
207+
_apply_response_attributes(span, result)
208+
_safe_invoke(extension.on_error, span, error)
209+
raise
210+
_apply_response_attributes(span, result)
211+
_safe_invoke(extension.on_success, span, result)
218212
finally:
219-
context_api.detach(token)
220213
_safe_invoke(extension.after_service_call)
221-
222214
self._call_response_hook(span, call_context, result)
223215

224216
return result

instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@
2727
)
2828

2929
from opentelemetry import trace as trace_api
30-
from opentelemetry.context import (
31-
_SUPPRESS_HTTP_INSTRUMENTATION_KEY,
32-
attach,
33-
detach,
34-
set_value,
35-
)
3630
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
37-
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
31+
from opentelemetry.instrumentation.utils import (
32+
suppress_http_instrumentation,
33+
suppress_instrumentation,
34+
)
3835
from opentelemetry.propagate import get_global_textmap, set_global_textmap
3936
from opentelemetry.propagators.aws.aws_xray_propagator import TRACE_HEADER_KEY
4037
from opentelemetry.semconv.trace import SpanAttributes
@@ -341,23 +338,17 @@ def check_headers(**kwargs):
341338
@mock_xray
342339
def test_suppress_instrumentation_xray_client(self):
343340
xray_client = self._make_client("xray")
344-
token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True))
345-
try:
341+
with suppress_instrumentation():
346342
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])
347343
xray_client.put_trace_segments(TraceSegmentDocuments=["str2"])
348-
finally:
349-
detach(token)
350344
self.assertEqual(0, len(self.get_finished_spans()))
351345

352346
@mock_xray
353347
def test_suppress_http_instrumentation_xray_client(self):
354348
xray_client = self._make_client("xray")
355-
token = attach(set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True))
356-
try:
349+
with suppress_http_instrumentation():
357350
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])
358351
xray_client.put_trace_segments(TraceSegmentDocuments=["str2"])
359-
finally:
360-
detach(token)
361352
self.assertEqual(2, len(self.get_finished_spans()))
362353

363354
@mock_s3

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def response_hook(span: Span, status: str, response_headers: List):
141141
if span and span.is_recording():
142142
span.set_attribute("custom_user_attribute_from_response_hook", "some-value")
143143
144-
FlaskInstrumentation().instrument(request_hook=request_hook, response_hook=response_hook)
144+
FlaskInstrumentor().instrument(request_hook=request_hook, response_hook=response_hook)
145145
146146
Flask Request object reference: https://flask.palletsprojects.com/en/2.1.x/api/#flask.Request
147147

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
import grpc
2020
from grpc.aio import ClientCallDetails
2121

22-
from opentelemetry import context
2322
from opentelemetry.instrumentation.grpc._client import (
2423
OpenTelemetryClientInterceptor,
2524
_carrier_setter,
2625
)
27-
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
26+
from opentelemetry.instrumentation.utils import is_instrumentation_enabled
2827
from opentelemetry.propagate import inject
2928
from opentelemetry.semconv.trace import SpanAttributes
3029
from opentelemetry.trace.status import Status, StatusCode
@@ -139,9 +138,10 @@ async def _wrap_stream_response(self, span, call):
139138
span.end()
140139

141140
def tracing_skipped(self, client_call_details):
142-
return context.get_value(
143-
_SUPPRESS_INSTRUMENTATION_KEY
144-
) or not self.rpc_matches_filters(client_call_details)
141+
return (
142+
not is_instrumentation_enabled()
143+
or not self.rpc_matches_filters(client_call_details)
144+
)
145145

146146
def rpc_matches_filters(self, client_call_details):
147147
return self._filter is None or self._filter(client_call_details)

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
import grpc
2727

28-
from opentelemetry import context, trace
28+
from opentelemetry import trace
2929
from opentelemetry.instrumentation.grpc import grpcext
3030
from opentelemetry.instrumentation.grpc._utilities import RpcInfo
31-
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
31+
from opentelemetry.instrumentation.utils import is_instrumentation_enabled
3232
from opentelemetry.propagate import inject
3333
from opentelemetry.propagators.textmap import Setter
3434
from opentelemetry.semconv.trace import SpanAttributes
@@ -123,7 +123,7 @@ def _trace_result(self, span, rpc_info, result):
123123
return result
124124

125125
def _intercept(self, request, metadata, client_info, invoker):
126-
if context.get_value(_SUPPRESS_INSTRUMENTATION_KEY):
126+
if not is_instrumentation_enabled():
127127
return invoker(request, metadata)
128128

129129
if not metadata:
@@ -219,7 +219,7 @@ def _intercept_server_stream(
219219
def intercept_stream(
220220
self, request_or_iterator, metadata, client_info, invoker
221221
):
222-
if context.get_value(_SUPPRESS_INSTRUMENTATION_KEY):
222+
if not is_instrumentation_enabled():
223223
return invoker(request_or_iterator, metadata)
224224

225225
if self._filter is not None and not self._filter(client_info):

0 commit comments

Comments
 (0)