From eb03dac1f0553bc7a2f0249013a7f88e4b3928a1 Mon Sep 17 00:00:00 2001 From: Diego Amaral Date: Wed, 11 Dec 2024 10:35:50 -0300 Subject: [PATCH 1/2] NoOpTracerProvider test case for botocore instrumentation (#3091) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> --- .../tests/test_botocore_instrumentation.py | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 62357a3336..fa8b497904 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -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() @@ -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") @@ -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") @@ -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") @@ -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 = {} @@ -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 = {} @@ -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 = {} From d2a51b95e54089a59fb36b3390aee1b6acf2b937 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Wed, 11 Dec 2024 16:02:37 +0100 Subject: [PATCH 2/2] docs: move `AwsLambdaInstrumentor().instrument()` to after the lambda function (#3085) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> --- .../src/opentelemetry/instrumentation/aws_lambda/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py index 68db87ca30..b31e6dea72 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py @@ -29,7 +29,6 @@ # Enable instrumentation BotocoreInstrumentor().instrument() - AwsLambdaInstrumentor().instrument() # Lambda function def lambda_handler(event, context): @@ -39,6 +38,8 @@ def lambda_handler(event, context): return "200 OK" + AwsLambdaInstrumentor().instrument() + API ---