Skip to content

Commit 44c78a2

Browse files
author
alrex
authored
instrumentation/botocore: fix failing test (#1100)
The failing test was introduced I believe by a change in behaviour noted in this issue: getmoto/moto#3292. The solution is to set a region in the create_bucket call. Fixes #1088
1 parent c26f783 commit 44c78a2

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py

+30-29
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,36 @@ def test_s3_client(self):
104104
)
105105

106106
# Comment test for issue 1088
107-
# @mock_s3
108-
# def test_s3_put(self):
109-
# params = dict(Key="foo", Bucket="mybucket", Body=b"bar")
110-
# s3 = self.session.create_client("s3", region_name="us-west-2")
111-
# s3.create_bucket(Bucket="mybucket")
112-
# s3.put_object(**params)
113-
114-
# spans = self.memory_exporter.get_finished_spans()
115-
# assert spans
116-
# span = spans[0]
117-
# self.assertEqual(len(spans), 2)
118-
# self.assertEqual(span.attributes["aws.operation"], "CreateBucket")
119-
# assert_span_http_status_code(span, 200)
120-
# self.assertEqual(
121-
# span.resource,
122-
# Resource(
123-
# attributes={"endpoint": "s3", "operation": "createbucket"}
124-
# ),
125-
# )
126-
# self.assertEqual(spans[1].attributes["aws.operation"], "PutObject")
127-
# self.assertEqual(
128-
# spans[1].resource,
129-
# Resource(attributes={"endpoint": "s3", "operation": "putobject"}),
130-
# )
131-
# self.assertEqual(spans[1].attributes["params.Key"], str(params["Key"]))
132-
# self.assertEqual(
133-
# spans[1].attributes["params.Bucket"], str(params["Bucket"])
134-
# )
135-
# self.assertTrue("params.Body" not in spans[1].attributes.keys())
107+
@mock_s3
108+
def test_s3_put(self):
109+
params = dict(Key="foo", Bucket="mybucket", Body=b"bar")
110+
s3 = self.session.create_client("s3", region_name="us-west-2")
111+
location = {"LocationConstraint": "us-west-2"}
112+
s3.create_bucket(Bucket="mybucket", CreateBucketConfiguration=location)
113+
s3.put_object(**params)
114+
115+
spans = self.memory_exporter.get_finished_spans()
116+
assert spans
117+
span = spans[0]
118+
self.assertEqual(len(spans), 2)
119+
self.assertEqual(span.attributes["aws.operation"], "CreateBucket")
120+
assert_span_http_status_code(span, 200)
121+
self.assertEqual(
122+
span.resource,
123+
Resource(
124+
attributes={"endpoint": "s3", "operation": "createbucket"}
125+
),
126+
)
127+
self.assertEqual(spans[1].attributes["aws.operation"], "PutObject")
128+
self.assertEqual(
129+
spans[1].resource,
130+
Resource(attributes={"endpoint": "s3", "operation": "putobject"}),
131+
)
132+
self.assertEqual(spans[1].attributes["params.Key"], str(params["Key"]))
133+
self.assertEqual(
134+
spans[1].attributes["params.Bucket"], str(params["Bucket"])
135+
)
136+
self.assertTrue("params.Body" not in spans[1].attributes.keys())
136137

137138
@mock_sqs
138139
def test_sqs_client(self):

0 commit comments

Comments
 (0)