18
18
from botocore .exceptions import ParamValidationError
19
19
from moto import ( # pylint: disable=import-error
20
20
mock_ec2 ,
21
+ mock_dynamodb2 ,
21
22
mock_kinesis ,
22
23
mock_kms ,
23
24
mock_lambda ,
@@ -61,6 +62,7 @@ def test_traced_client(self):
61
62
{
62
63
"aws.operation" : "DescribeInstances" ,
63
64
"aws.region" : "us-west-2" ,
65
+ "aws.request_id" : "fdcdcab1-ae5c-489e-9c33-4637c5dda355" ,
64
66
"aws.service" : "ec2" ,
65
67
"http.status_code" : 200 ,
66
68
},
@@ -103,7 +105,6 @@ def test_s3_client(self):
103
105
assert spans
104
106
span = spans [0 ]
105
107
self .assertEqual (len (spans ), 2 )
106
- self .assertEqual (span .attributes ["aws.operation" ], "ListBuckets" )
107
108
self .assertEqual (
108
109
dict (span .attributes ),
109
110
{
@@ -138,21 +139,24 @@ def test_s3_put(self):
138
139
location = {"LocationConstraint" : "us-west-2" }
139
140
s3 .create_bucket (Bucket = "mybucket" , CreateBucketConfiguration = location )
140
141
s3 .put_object (** params )
142
+ s3 .get_object (Bucket = "mybucket" , Key = "foo" )
141
143
142
144
spans = self .memory_exporter .get_finished_spans ()
143
145
assert spans
144
- self .assertEqual (len (spans ), 2 )
146
+ self .assertEqual (len (spans ), 3 )
147
+ create_bucket_attributes = dict (spans [0 ].attributes )
145
148
self .assertEqual (
146
- spans [ 0 ]. attributes ,
149
+ create_bucket_attributes ,
147
150
{
148
151
"aws.operation" : "CreateBucket" ,
149
152
"aws.region" : "us-west-2" ,
150
153
"aws.service" : "s3" ,
151
154
"http.status_code" : 200 ,
152
155
},
153
156
)
157
+ put_object_attributes = dict (spans [1 ].attributes )
154
158
self .assertEqual (
155
- spans [ 1 ]. attributes ,
159
+ put_object_attributes ,
156
160
{
157
161
"aws.operation" : "PutObject" ,
158
162
"aws.region" : "us-west-2" ,
@@ -161,6 +165,16 @@ def test_s3_put(self):
161
165
},
162
166
)
163
167
self .assertTrue ("params.Body" not in spans [1 ].attributes .keys ())
168
+ get_object_attributes = dict (spans [2 ].attributes )
169
+ self .assertEqual (
170
+ get_object_attributes ,
171
+ {
172
+ "aws.operation" : "GetObject" ,
173
+ "aws.region" : "us-west-2" ,
174
+ "aws.service" : "s3" ,
175
+ "http.status_code" : 200 ,
176
+ },
177
+ )
164
178
165
179
@mock_sqs
166
180
def test_sqs_client (self ):
@@ -172,8 +186,11 @@ def test_sqs_client(self):
172
186
assert spans
173
187
span = spans [0 ]
174
188
self .assertEqual (len (spans ), 1 )
189
+ actual = dict (span .attributes )
190
+ self .assertRegex (actual ["aws.request_id" ], r"[A-Z0-9]{52}" )
191
+ del actual ["aws.request_id" ]
175
192
self .assertEqual (
176
- dict ( span . attributes ) ,
193
+ actual ,
177
194
{
178
195
"aws.operation" : "ListQueues" ,
179
196
"aws.region" : "us-east-1" ,
@@ -182,6 +199,50 @@ def test_sqs_client(self):
182
199
},
183
200
)
184
201
202
+ @mock_sqs
203
+ def test_sqs_send_message (self ):
204
+ sqs = self .session .create_client ("sqs" , region_name = "us-east-1" )
205
+
206
+ TEST_QUEUE_NAME = 'test_queue_name'
207
+
208
+ response = sqs .create_queue (
209
+ QueueName = TEST_QUEUE_NAME
210
+ )
211
+
212
+ sqs .send_message (
213
+ QueueUrl = response ["QueueUrl" ],
214
+ MessageBody = "Test SQS MESSAGE!"
215
+ )
216
+
217
+ spans = self .memory_exporter .get_finished_spans ()
218
+ assert spans
219
+ self .assertEqual (len (spans ), 2 )
220
+ create_queue_attributes = dict (spans [0 ].attributes )
221
+ self .assertRegex (create_queue_attributes ["aws.request_id" ], r"[A-Z0-9]{52}" )
222
+ del create_queue_attributes ["aws.request_id" ]
223
+ self .assertEqual (
224
+ create_queue_attributes ,
225
+ {
226
+ "aws.operation" : "CreateQueue" ,
227
+ "aws.region" : "us-east-1" ,
228
+ "aws.service" : "sqs" ,
229
+ "http.status_code" : 200 ,
230
+ },
231
+ )
232
+ send_msg_attributes = dict (spans [1 ].attributes )
233
+ self .assertRegex (send_msg_attributes ["aws.request_id" ], r"[A-Z0-9]{52}" )
234
+ del send_msg_attributes ["aws.request_id" ]
235
+ self .assertEqual (
236
+ send_msg_attributes ,
237
+ {
238
+ "aws.operation" : "SendMessage" ,
239
+ "aws.queue_url" : response ["QueueUrl" ],
240
+ "aws.region" : "us-east-1" ,
241
+ "aws.service" : "sqs" ,
242
+ "http.status_code" : 200 ,
243
+ },
244
+ )
245
+
185
246
@mock_kinesis
186
247
def test_kinesis_client (self ):
187
248
kinesis = self .session .create_client (
@@ -287,10 +348,98 @@ def test_sts_client(self):
287
348
{
288
349
"aws.operation" : "GetCallerIdentity" ,
289
350
"aws.region" : "us-east-1" ,
351
+ "aws.request_id" : "c6104cbe-af31-11e0-8154-cbc7ccf896c7" ,
290
352
"aws.service" : "sts" ,
291
353
"http.status_code" : 200 ,
292
354
},
293
355
)
294
356
295
357
# checking for protection on sts against security leak
296
358
self .assertTrue ("params" not in span .attributes .keys ())
359
+
360
+ @mock_dynamodb2
361
+ def test_dynamodb_client (self ):
362
+ ddb = self .session .create_client ("dynamodb" , region_name = "us-west-2" )
363
+
364
+ TEST_TABLE_NAME = "test_table_name"
365
+
366
+ ddb .create_table (
367
+ AttributeDefinitions = [
368
+ {
369
+ 'AttributeName' : 'id' ,
370
+ 'AttributeType' : 'S' ,
371
+ },
372
+ ],
373
+ KeySchema = [
374
+ {
375
+ 'AttributeName' : 'id' ,
376
+ 'KeyType' : 'HASH' ,
377
+ },
378
+ ],
379
+ ProvisionedThroughput = {
380
+ 'ReadCapacityUnits' : 5 ,
381
+ 'WriteCapacityUnits' : 5 ,
382
+ },
383
+ TableName = TEST_TABLE_NAME ,
384
+ )
385
+
386
+ ddb .put_item (
387
+ TableName = TEST_TABLE_NAME ,
388
+ Item = {
389
+ 'id' : {
390
+ 'S' : 'test_key'
391
+ }
392
+ }
393
+ )
394
+
395
+ ddb .get_item (
396
+ TableName = TEST_TABLE_NAME ,
397
+ Key = {
398
+ 'id' : {
399
+ 'S' : 'test_key'
400
+ }
401
+ }
402
+ )
403
+
404
+ spans = self .memory_exporter .get_finished_spans ()
405
+ assert spans
406
+ self .assertEqual (len (spans ), 3 )
407
+ create_table_attributes = dict (spans [0 ].attributes )
408
+ self .assertRegex (create_table_attributes ["aws.request_id" ], r"[A-Z0-9]{52}" )
409
+ del create_table_attributes ["aws.request_id" ]
410
+ self .assertEqual (
411
+ create_table_attributes ,
412
+ {
413
+ "aws.operation" : "CreateTable" ,
414
+ "aws.region" : "us-west-2" ,
415
+ "aws.service" : "dynamodb" ,
416
+ "aws.table_name" : "test_table_name" ,
417
+ "http.status_code" : 200 ,
418
+ },
419
+ )
420
+ put_item_attributes = dict (spans [1 ].attributes )
421
+ self .assertRegex (put_item_attributes ["aws.request_id" ], r"[A-Z0-9]{52}" )
422
+ del put_item_attributes ["aws.request_id" ]
423
+ self .assertEqual (
424
+ put_item_attributes ,
425
+ {
426
+ "aws.operation" : "PutItem" ,
427
+ "aws.region" : "us-west-2" ,
428
+ "aws.service" : "dynamodb" ,
429
+ "aws.table_name" : "test_table_name" ,
430
+ "http.status_code" : 200 ,
431
+ },
432
+ )
433
+ get_item_attributes = dict (spans [2 ].attributes )
434
+ self .assertRegex (get_item_attributes ["aws.request_id" ], r"[A-Z0-9]{52}" )
435
+ del get_item_attributes ["aws.request_id" ]
436
+ self .assertEqual (
437
+ get_item_attributes ,
438
+ {
439
+ "aws.operation" : "GetItem" ,
440
+ "aws.region" : "us-west-2" ,
441
+ "aws.service" : "dynamodb" ,
442
+ "aws.table_name" : "test_table_name" ,
443
+ "http.status_code" : 200 ,
444
+ },
445
+ )
0 commit comments