mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 11:31:52 +08:00
Merge pull request #182 from NathanielRN/suppress-downstream-botocore-instrumentation
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
## Unreleased
|
||||
- Add propagator injection for botocore calls
|
||||
([#181](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/181))
|
||||
- Make botocore instrumentation check if instrumentation has been suppressed
|
||||
([#182](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/182))
|
||||
|
||||
## Version 0.13b0
|
||||
|
||||
|
@ -56,6 +56,7 @@ import logging
|
||||
from botocore.client import BaseClient
|
||||
from wrapt import ObjectProxy, wrap_function_wrapper
|
||||
|
||||
from opentelemetry import context as context_api
|
||||
from opentelemetry import propagators
|
||||
from opentelemetry.instrumentation.botocore.version import __version__
|
||||
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
||||
@ -104,6 +105,8 @@ class BotocoreInstrumentor(BaseInstrumentor):
|
||||
unwrap(BaseClient, "_make_api_call")
|
||||
|
||||
def _patched_api_call(self, original_func, instance, args, kwargs):
|
||||
if context_api.get_value("suppress_instrumentation"):
|
||||
return original_func(*args, **kwargs)
|
||||
|
||||
endpoint_name = deep_getattr(instance, "_endpoint._endpoint_prefix")
|
||||
|
||||
|
@ -23,9 +23,11 @@ from moto import ( # pylint: disable=import-error
|
||||
mock_lambda,
|
||||
mock_s3,
|
||||
mock_sqs,
|
||||
mock_xray,
|
||||
)
|
||||
|
||||
from opentelemetry import propagators
|
||||
from opentelemetry.context import attach, detach, set_value
|
||||
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
|
||||
from opentelemetry.sdk.resources import Resource
|
||||
from opentelemetry.test.mock_textmap import MockTextMapPropagator
|
||||
@ -330,3 +332,16 @@ class TestBotocoreInstrumentor(TestBase):
|
||||
|
||||
finally:
|
||||
propagators.set_global_textmap(previous_propagator)
|
||||
|
||||
@mock_xray
|
||||
def test_suppress_instrumentation_xray_client(self):
|
||||
xray_client = self.session.create_client(
|
||||
"xray", region_name="us-east-1"
|
||||
)
|
||||
token = attach(set_value("suppress_instrumentation", True))
|
||||
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])
|
||||
xray_client.put_trace_segments(TraceSegmentDocuments=["str2"])
|
||||
detach(token)
|
||||
|
||||
spans = self.memory_exporter.get_finished_spans()
|
||||
self.assertEqual(0, len(spans))
|
||||
|
Reference in New Issue
Block a user