Skip to content

Commit d78266c

Browse files
committed
Support table queue and requests attributes
1 parent 1ac5ac6 commit d78266c

File tree

1 file changed

+36
-9
lines changed
  • instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore

1 file changed

+36
-9
lines changed

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py

+36-9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import logging
5555

5656
from botocore.client import BaseClient
57+
from botocore.exceptions import ClientError
5758
from wrapt import ObjectProxy, wrap_function_wrapper
5859

5960
from opentelemetry.instrumentation.botocore.version import __version__
@@ -91,23 +92,49 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
9192

9293
# pylint: disable=protected-access
9394
service_name = instance._service_model.service_name
94-
operation_name, _ = args
95+
operation_name, api_params = args
9596

9697
with self._tracer.start_as_current_span(
9798
"{}".format(service_name), kind=SpanKind.CLIENT,
9899
) 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
99110

100111
if span.is_recording():
101112
span.set_attribute("aws.operation", operation_name)
102113
span.set_attribute("aws.region", instance.meta.region_name)
103114
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
112139

113140
return result

0 commit comments

Comments
 (0)