|
4 | 4 | from botocore.errorfactory import ClientError |
5 | 5 |
|
6 | 6 | from ddtrace.contrib.aiobotocore.patch import patch, unpatch |
| 7 | +from ddtrace.ext import http |
| 8 | +from ddtrace.compat import stringify |
7 | 9 |
|
8 | 10 | from .utils import aiobotocore_client |
9 | 11 | from ..asyncio.utils import AsyncioTestCase, mark_asyncio |
@@ -59,11 +61,33 @@ def test_s3_client(self): |
59 | 61 | eq_(span.resource, 's3.listbuckets') |
60 | 62 | eq_(span.name, 's3.command') |
61 | 63 |
|
| 64 | + @mark_asyncio |
| 65 | + def test_s3_put(self): |
| 66 | + params = dict(Key='foo', Bucket='mybucket', Body=b'bar') |
| 67 | + |
| 68 | + with aiobotocore_client('s3', self.tracer) as s3: |
| 69 | + yield from s3.create_bucket(Bucket='mybucket') |
| 70 | + yield from s3.put_object(**params) |
| 71 | + |
| 72 | + spans = [trace[0] for trace in self.tracer.writer.pop_traces()] |
| 73 | + assert spans |
| 74 | + self.assertEqual(len(spans), 2) |
| 75 | + self.assertEqual(spans[0].get_tag('aws.operation'), 'CreateBucket') |
| 76 | + self.assertEqual(spans[0].get_tag(http.STATUS_CODE), '200') |
| 77 | + self.assertEqual(spans[0].service, 'aws.s3') |
| 78 | + self.assertEqual(spans[0].resource, 's3.createbucket') |
| 79 | + self.assertEqual(spans[1].get_tag('aws.operation'), 'PutObject') |
| 80 | + self.assertEqual(spans[1].resource, 's3.putobject') |
| 81 | + self.assertEqual(spans[1].get_tag('params.Key'), stringify(params['Key'])) |
| 82 | + self.assertEqual(spans[1].get_tag('params.Bucket'), stringify(params['Bucket'])) |
| 83 | + self.assertEqual(spans[1].get_tag('params.Body'), stringify(params['Body'])) |
| 84 | + |
62 | 85 | @mark_asyncio |
63 | 86 | def test_s3_client_error(self): |
64 | 87 | with aiobotocore_client('s3', self.tracer) as s3: |
65 | 88 | with assert_raises(ClientError): |
66 | | - yield from s3.list_objects(Bucket='mybucket') |
| 89 | + # FIXME: add proper clean-up to tearDown |
| 90 | + yield from s3.list_objects(Bucket='doesnotexist') |
67 | 91 |
|
68 | 92 | traces = self.tracer.writer.pop_traces() |
69 | 93 | eq_(len(traces), 1) |
|
0 commit comments