Skip to content

Commit 1a7e632

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

File tree

1 file changed

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

1 file changed

+10
-4
lines changed

src/instana/instrumentation/aws/s3.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# (c) Copyright Instana Inc. 2020
33

44
try:
5+
import contextlib
56
from typing import TYPE_CHECKING, Any, Callable, Dict, Sequence, Type
67

78
from instana.span_context import SpanContext
@@ -57,16 +58,21 @@ def collect_s3_injected_attributes(
5758
with tracer.start_as_current_span("s3", span_context=parent_context) as span:
5859
try:
5960
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])
61+
# Suppress key/index errors to all the function to still happen
62+
with contextlib.suppress(IndexError, KeyError):
63+
if "Bucket" in kwargs:
64+
span.set_attribute("s3.bucket", kwargs["Bucket"])
65+
elif wrapped.__name__ in ["download_file", "download_fileobj"]:
66+
span.set_attribute("s3.bucket", args[0])
67+
else:
68+
span.set_attribute("s3.bucket", args[1])
6469
return wrapped(*args, **kwargs)
6570
except Exception as exc:
6671
span.record_exception(exc)
6772
logger.debug(
6873
"collect_s3_injected_attributes: collect error", exc_info=True
6974
)
75+
raise exc
7076

7177
for method in [
7278
"upload_file",

0 commit comments

Comments
 (0)