Skip to content

Commit 2460373

Browse files
committed
Update AWS wrapper to not hide exceptions
Signed-off-by: Michael Honaker <[email protected]>
1 parent e9820b9 commit 2460373

File tree

1 file changed

+12
-4
lines changed
  • src/instana/instrumentation/aws

1 file changed

+12
-4
lines changed

src/instana/instrumentation/aws/s3.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# (c) Copyright IBM Corp. 2021
22
# (c) Copyright Instana Inc. 2020
33

4+
import contextlib
5+
6+
47
try:
58
from typing import TYPE_CHECKING, Any, Callable, Dict, Sequence, Type
69

@@ -57,16 +60,21 @@ def collect_s3_injected_attributes(
5760
with tracer.start_as_current_span("s3", span_context=parent_context) as span:
5861
try:
5962
span.set_attribute("s3.op", operations[wrapped.__name__])
60-
if wrapped.__name__ in ["download_file", "download_fileobj"]:
61-
span.set_attribute("s3.bucket", args[0])
62-
else:
63-
span.set_attribute("s3.bucket", args[1])
63+
# Suppress key/index errors to all the function to still happen
64+
with contextlib.suppress(IndexError, KeyError):
65+
if "Bucket" in kwargs:
66+
span.set_attribute("s3.bucket", kwargs["Bucket"])
67+
elif wrapped.__name__ in ["download_file", "download_fileobj"]:
68+
span.set_attribute("s3.bucket", args[0])
69+
else:
70+
span.set_attribute("s3.bucket", args[1])
6471
return wrapped(*args, **kwargs)
6572
except Exception as exc:
6673
span.record_exception(exc)
6774
logger.debug(
6875
"collect_s3_injected_attributes: collect error", exc_info=True
6976
)
77+
raise exc
7078

7179
for method in [
7280
"upload_file",

0 commit comments

Comments
 (0)