Skip to content

Commit b0c02de

Browse files
committed
Botocore instrumentation checks if it has been suppressed
1 parent cb70679 commit b0c02de

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Diff for: instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from botocore.client import BaseClient
5757
from wrapt import ObjectProxy, wrap_function_wrapper
5858

59+
from opentelemetry import context as context_api
5960
from opentelemetry.instrumentation.botocore.version import __version__
6061
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6162
from opentelemetry.sdk.trace import Resource
@@ -89,6 +90,8 @@ def _uninstrument(self, **kwargs):
8990
unwrap(BaseClient, "_make_api_call")
9091

9192
def _patched_api_call(self, original_func, instance, args, kwargs):
93+
if context_api.get_value("suppress_instrumentation"):
94+
return original_func(*args, **kwargs)
9295

9396
endpoint_name = deep_getattr(instance, "_endpoint._endpoint_prefix")
9497

Diff for: instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py

+15
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
mock_lambda,
2424
mock_s3,
2525
mock_sqs,
26+
mock_xray,
2627
)
2728

29+
from opentelemetry.context import attach, detach, set_value
2830
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
2931
from opentelemetry.sdk.resources import Resource
3032
from opentelemetry.test.test_base import TestBase
@@ -275,3 +277,16 @@ def test_kms_client(self):
275277

276278
# checking for protection on sts against security leak
277279
self.assertTrue("params" not in span.attributes.keys())
280+
281+
@mock_xray
282+
def test_suppress_instrumentation_xray_client(self):
283+
xray_client = self.session.create_client(
284+
"xray", region_name="us-east-1"
285+
)
286+
token = attach(set_value("suppress_instrumentation", True))
287+
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])
288+
xray_client.put_trace_segments(TraceSegmentDocuments=["str2"])
289+
detach(token)
290+
291+
spans = self.memory_exporter.get_finished_spans()
292+
self.assertEqual(0, len(spans))

0 commit comments

Comments
 (0)