Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suppress instrument boto3 XRay.put_trace_segments() #1291

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from botocore.client import BaseClient
from wrapt import ObjectProxy, wrap_function_wrapper

from opentelemetry import context as context_api
from opentelemetry.instrumentation.botocore.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.sdk.trace import Resource
Expand Down Expand Up @@ -89,6 +90,8 @@ def _uninstrument(self, **kwargs):
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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
mock_lambda,
mock_s3,
mock_sqs,
mock_xray,
)

from opentelemetry.context import attach, detach, set_value
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
from opentelemetry.sdk.resources import Resource
from opentelemetry.test.test_base import TestBase
Expand Down Expand Up @@ -275,3 +277,16 @@ def test_kms_client(self):

# checking for protection on sts against security leak
self.assertTrue("params" not in span.attributes.keys())

@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))