From 44c78a2483f7bcdff0e1e942f9517c55f28c5d69 Mon Sep 17 00:00:00 2001 From: alrex Date: Mon, 14 Sep 2020 12:49:52 -0700 Subject: [PATCH] instrumentation/botocore: fix failing test (#1100) The failing test was introduced I believe by a change in behaviour noted in this issue: https://github.com/spulec/moto/issues/3292. The solution is to set a region in the create_bucket call. Fixes #1088 --- .../tests/test_botocore_instrumentation.py | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 64c9d0240279..ea655c883060 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -104,35 +104,36 @@ def test_s3_client(self): ) # Comment test for issue 1088 - # @mock_s3 - # def test_s3_put(self): - # params = dict(Key="foo", Bucket="mybucket", Body=b"bar") - # s3 = self.session.create_client("s3", region_name="us-west-2") - # s3.create_bucket(Bucket="mybucket") - # s3.put_object(**params) - - # spans = self.memory_exporter.get_finished_spans() - # assert spans - # span = spans[0] - # self.assertEqual(len(spans), 2) - # self.assertEqual(span.attributes["aws.operation"], "CreateBucket") - # assert_span_http_status_code(span, 200) - # self.assertEqual( - # span.resource, - # Resource( - # attributes={"endpoint": "s3", "operation": "createbucket"} - # ), - # ) - # self.assertEqual(spans[1].attributes["aws.operation"], "PutObject") - # self.assertEqual( - # spans[1].resource, - # Resource(attributes={"endpoint": "s3", "operation": "putobject"}), - # ) - # self.assertEqual(spans[1].attributes["params.Key"], str(params["Key"])) - # self.assertEqual( - # spans[1].attributes["params.Bucket"], str(params["Bucket"]) - # ) - # self.assertTrue("params.Body" not in spans[1].attributes.keys()) + @mock_s3 + def test_s3_put(self): + params = dict(Key="foo", Bucket="mybucket", Body=b"bar") + s3 = self.session.create_client("s3", region_name="us-west-2") + location = {"LocationConstraint": "us-west-2"} + s3.create_bucket(Bucket="mybucket", CreateBucketConfiguration=location) + s3.put_object(**params) + + spans = self.memory_exporter.get_finished_spans() + assert spans + span = spans[0] + self.assertEqual(len(spans), 2) + self.assertEqual(span.attributes["aws.operation"], "CreateBucket") + assert_span_http_status_code(span, 200) + self.assertEqual( + span.resource, + Resource( + attributes={"endpoint": "s3", "operation": "createbucket"} + ), + ) + self.assertEqual(spans[1].attributes["aws.operation"], "PutObject") + self.assertEqual( + spans[1].resource, + Resource(attributes={"endpoint": "s3", "operation": "putobject"}), + ) + self.assertEqual(spans[1].attributes["params.Key"], str(params["Key"])) + self.assertEqual( + spans[1].attributes["params.Bucket"], str(params["Bucket"]) + ) + self.assertTrue("params.Body" not in spans[1].attributes.keys()) @mock_sqs def test_sqs_client(self):