|
54 | 54 | import logging
|
55 | 55 |
|
56 | 56 | from botocore.client import BaseClient
|
| 57 | +from botocore.exceptions import ClientError |
57 | 58 | from wrapt import ObjectProxy, wrap_function_wrapper
|
58 | 59 |
|
59 | 60 | from opentelemetry.instrumentation.botocore.version import __version__
|
@@ -91,23 +92,49 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
|
91 | 92 |
|
92 | 93 | # pylint: disable=protected-access
|
93 | 94 | service_name = instance._service_model.service_name
|
94 |
| - operation_name, _ = args |
| 95 | + operation_name, api_params = args |
95 | 96 |
|
96 | 97 | with self._tracer.start_as_current_span(
|
97 | 98 | "{}".format(service_name), kind=SpanKind.CLIENT,
|
98 | 99 | ) as span:
|
| 100 | + error = None |
| 101 | + result = None |
| 102 | + |
| 103 | + try: |
| 104 | + result = original_func(*args, **kwargs) |
| 105 | + except ClientError as e: |
| 106 | + error = e |
| 107 | + |
| 108 | + if error: |
| 109 | + result = error.response |
99 | 110 |
|
100 | 111 | if span.is_recording():
|
101 | 112 | span.set_attribute("aws.operation", operation_name)
|
102 | 113 | span.set_attribute("aws.region", instance.meta.region_name)
|
103 | 114 | span.set_attribute("aws.service", service_name)
|
104 |
| - |
105 |
| - result = original_func(*args, **kwargs) |
106 |
| - |
107 |
| - if span.is_recording(): |
108 |
| - span.set_attribute( |
109 |
| - "http.status_code", |
110 |
| - result["ResponseMetadata"]["HTTPStatusCode"], |
111 |
| - ) |
| 115 | + if "QueueUrl" in api_params: |
| 116 | + span.set_attribute( |
| 117 | + "aws.queue_url", |
| 118 | + api_params["QueueUrl"] |
| 119 | + ) |
| 120 | + if "TableName" in api_params: |
| 121 | + span.set_attribute( |
| 122 | + "aws.table_name", |
| 123 | + api_params["TableName"] |
| 124 | + ) |
| 125 | + if "ResponseMetadata" in result: |
| 126 | + if "RequestId" in result["ResponseMetadata"]: |
| 127 | + span.set_attribute( |
| 128 | + "aws.request_id", |
| 129 | + result["ResponseMetadata"]["RequestId"], |
| 130 | + ) |
| 131 | + if "HTTPStatusCode" in result["ResponseMetadata"]: |
| 132 | + span.set_attribute( |
| 133 | + "http.status_code", |
| 134 | + result["ResponseMetadata"]["HTTPStatusCode"], |
| 135 | + ) |
| 136 | + |
| 137 | + if error: |
| 138 | + raise error |
112 | 139 |
|
113 | 140 | return result
|
0 commit comments