Skip to content

Commit

Permalink
NoOpTracerProvider test case for botocore instrumentation (#3091)
Browse files Browse the repository at this point in the history
Co-authored-by: Emídio Neto <[email protected]>
  • Loading branch information
dgoscn and emdneto authored Dec 11, 2024
1 parent 8302310 commit eb03dac
Showing 1 changed file with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ def test_traced_client(self):
request_id = "fdcdcab1-ae5c-489e-9c33-4637c5dda355"
self.assert_span("EC2", "DescribeInstances", request_id=request_id)

@mock_aws
def test_no_op_tracer_provider_ec2(self):
BotocoreInstrumentor().uninstrument()
BotocoreInstrumentor().instrument(
tracer_provider=trace_api.NoOpTracerProvider()
)

ec2 = self._make_client("ec2")
ec2.describe_instances()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock_aws
def test_not_recording(self):
mock_tracer = Mock()
Expand Down Expand Up @@ -148,6 +161,19 @@ def test_s3_client(self):
s3.list_buckets()
self.assert_span("S3", "ListBuckets")

@mock_aws
def test_no_op_tracer_provider_s3(self):
BotocoreInstrumentor().uninstrument()
BotocoreInstrumentor().instrument(
tracer_provider=trace_api.NoOpTracerProvider()
)

s3 = self._make_client("s3")
s3.list_buckets()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock_aws
def test_s3_put(self):
s3 = self._make_client("s3")
Expand Down Expand Up @@ -176,6 +202,19 @@ def test_sqs_client(self):
"SQS", "ListQueues", request_id=_REQUEST_ID_REGEX_MATCH
)

@mock_aws
def test_no_op_tracer_provider_sqs(self):
BotocoreInstrumentor().uninstrument()
BotocoreInstrumentor().instrument(
tracer_provider=trace_api.NoOpTracerProvider()
)

sqs = self._make_client("sqs")
sqs.list_queues()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock_aws
def test_sqs_send_message(self):
sqs = self._make_client("sqs")
Expand Down Expand Up @@ -204,6 +243,19 @@ def test_kinesis_client(self):
kinesis.list_streams()
self.assert_span("Kinesis", "ListStreams")

@mock_aws
def test_no_op_tracer_provider_kinesis(self):
BotocoreInstrumentor().uninstrument()
BotocoreInstrumentor().instrument(
tracer_provider=trace_api.NoOpTracerProvider()
)

kinesis = self._make_client("kinesis")
kinesis.list_streams()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock_aws
def test_unpatch(self):
kinesis = self._make_client("kinesis")
Expand All @@ -213,6 +265,19 @@ def test_unpatch(self):
kinesis.list_streams()
self.assertEqual(0, len(self.memory_exporter.get_finished_spans()))

@mock_aws
def test_no_op_tracer_provider_kms(self):
BotocoreInstrumentor().uninstrument()
BotocoreInstrumentor().instrument(
tracer_provider=trace_api.NoOpTracerProvider()
)

kms = self._make_client("kms")
kms.list_keys(Limit=21)

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock_aws
def test_uninstrument_does_not_inject_headers(self):
headers = {}
Expand Down Expand Up @@ -268,6 +333,19 @@ def test_sts_client(self):
# check for exact attribute set to make sure not to leak any sts secrets
self.assertEqual(expected, dict(span.attributes))

@mock_aws
def test_no_op_tracer_provider_sts(self):
BotocoreInstrumentor().uninstrument()
BotocoreInstrumentor().instrument(
tracer_provider=trace_api.NoOpTracerProvider()
)

sts = self._make_client("sts")
sts.get_caller_identity()

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock_aws
def test_propagator_injects_into_request(self):
headers = {}
Expand Down Expand Up @@ -308,6 +386,19 @@ def check_headers(**kwargs):
finally:
set_global_textmap(previous_propagator)

@mock_aws
def test_no_op_tracer_provider_xray(self):
BotocoreInstrumentor().uninstrument()
BotocoreInstrumentor().instrument(
tracer_provider=trace_api.NoOpTracerProvider()
)

xray_client = self._make_client("xray")
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock_aws
def test_override_xray_propagator_injects_into_request(self):
headers = {}
Expand Down

0 comments on commit eb03dac

Please sign in to comment.