13
13
# limitations under the License.
14
14
import io
15
15
import json
16
+ import sys
16
17
import zipfile
17
18
from unittest .mock import Mock , patch
18
19
30
31
mock_sts ,
31
32
mock_xray ,
32
33
)
34
+ from pytest import mark
33
35
34
36
from opentelemetry import trace as trace_api
35
37
from opentelemetry .context import attach , detach , set_value
@@ -128,12 +130,13 @@ def test_s3_client(self):
128
130
s3 .list_buckets ()
129
131
s3 .list_buckets ()
130
132
131
- spans = self .memory_exporter . get_finished_spans ()
133
+ spans = self .get_finished_spans ()
132
134
assert spans
133
- span = spans [0 ]
134
135
self .assertEqual (len (spans ), 2 )
135
- self .assertEqual (
136
- span .attributes ,
136
+
137
+ buckets_span = spans .by_attr ("aws.operation" , "ListBuckets" )
138
+ self .assertSpanHasAttributes (
139
+ buckets_span ,
137
140
{
138
141
"aws.operation" : "ListBuckets" ,
139
142
"aws.region" : "us-west-2" ,
@@ -144,22 +147,21 @@ def test_s3_client(self):
144
147
)
145
148
146
149
# testing for span error
147
- self .memory_exporter .get_finished_spans ()
148
150
with self .assertRaises (ParamValidationError ):
149
151
s3 .list_objects (bucket = "mybucket" )
150
- spans = self .memory_exporter . get_finished_spans ()
152
+ spans = self .get_finished_spans ()
151
153
assert spans
152
- span = spans [ 2 ]
153
- self .assertEqual (
154
- span . attributes ,
154
+ objects_span = spans . by_attr ( "aws.operation" , "ListObjects" )
155
+ self .assertSpanHasAttributes (
156
+ objects_span ,
155
157
{
156
158
"aws.operation" : "ListObjects" ,
157
159
"aws.region" : "us-west-2" ,
158
160
"aws.service" : "s3" ,
159
161
},
160
162
)
161
163
self .assertIs (
162
- span .status .status_code , trace_api .StatusCode .ERROR ,
164
+ objects_span .status .status_code , trace_api .StatusCode .ERROR ,
163
165
)
164
166
165
167
# Comment test for issue 1088
@@ -172,12 +174,13 @@ def test_s3_put(self):
172
174
s3 .put_object (** params )
173
175
s3 .get_object (Bucket = "mybucket" , Key = "foo" )
174
176
175
- spans = self .memory_exporter . get_finished_spans ()
177
+ spans = self .get_finished_spans ()
176
178
assert spans
177
179
self .assertEqual (len (spans ), 3 )
178
- create_bucket_attributes = spans [0 ].attributes
179
- self .assertEqual (
180
- create_bucket_attributes ,
180
+
181
+ create_span = spans .by_attr ("aws.operation" , "CreateBucket" )
182
+ self .assertSpanHasAttributes (
183
+ create_span ,
181
184
{
182
185
"aws.operation" : "CreateBucket" ,
183
186
"aws.region" : "us-west-2" ,
@@ -186,9 +189,10 @@ def test_s3_put(self):
186
189
SpanAttributes .HTTP_STATUS_CODE : 200 ,
187
190
},
188
191
)
189
- put_object_attributes = spans [1 ].attributes
190
- self .assertEqual (
191
- put_object_attributes ,
192
+
193
+ put_span = spans .by_attr ("aws.operation" , "PutObject" )
194
+ self .assertSpanHasAttributes (
195
+ put_span ,
192
196
{
193
197
"aws.operation" : "PutObject" ,
194
198
"aws.region" : "us-west-2" ,
@@ -197,10 +201,12 @@ def test_s3_put(self):
197
201
SpanAttributes .HTTP_STATUS_CODE : 200 ,
198
202
},
199
203
)
200
- self .assertTrue ("params.Body" not in spans [1 ].attributes .keys ())
201
- get_object_attributes = spans [2 ].attributes
202
- self .assertEqual (
203
- get_object_attributes ,
204
+ self .assertTrue ("params.Body" not in put_span .attributes .keys ())
205
+
206
+ get_span = spans .by_attr ("aws.operation" , "GetObject" )
207
+
208
+ self .assertSpanHasAttributes (
209
+ get_span ,
204
210
{
205
211
"aws.operation" : "GetObject" ,
206
212
"aws.region" : "us-west-2" ,
@@ -359,6 +365,10 @@ def get_role_name(self):
359
365
Path = "/my-path/" ,
360
366
)["Role" ]["Arn" ]
361
367
368
+ @mark .skipif (
369
+ sys .platform == "win32" ,
370
+ reason = "requires docker and Github CI Windows does not have docker installed by default" ,
371
+ )
362
372
@mock_lambda
363
373
def test_lambda_invoke_propagation (self ):
364
374
0 commit comments