Skip to content

opentelemetry-instrumentation-boto3sqs: avoid KeyError when all messages in send_message_batch fail#4746

Open
ferencjuhasz wants to merge 2 commits into
open-telemetry:mainfrom
ferencjuhasz:boto3sqs-fix-send-batch-successful-keyerror
Open

opentelemetry-instrumentation-boto3sqs: avoid KeyError when all messages in send_message_batch fail#4746
ferencjuhasz wants to merge 2 commits into
open-telemetry:mainfrom
ferencjuhasz:boto3sqs-fix-send-batch-successful-keyerror

Conversation

@ferencjuhasz

Copy link
Copy Markdown

Description

Boto3SQSInstrumentor's send_message_batch wrapper unconditionally indexes retval["Successful"]:

retval = wrapped(*args, **kwargs)
for successful_messages in retval["Successful"]:

When every entry in a batch fails, the SQS SendMessageBatch response contains only Failed and omits the Successful key entirely. The wrapper then raises KeyError: 'Successful'. Because this happens inside the instrumentation wrapper, the exception propagates out of client.send_message_batch and breaks the caller — even though the failure is an ordinary per-message batch failure the application is expected to handle from the response.

File ".../boto3/resources/action.py", line 88, in __call__
File ".../opentelemetry/instrumentation/boto3sqs/__init__.py", line 270, in send_batch_wrapper
    for successful_messages in retval["Successful"]:
KeyError: 'Successful'

Fix

Iterate over retval.get("Successful", []). Spans for failed entries are still created and ended by the existing loop, so tracing behavior is otherwise unchanged.

Tests

The send_message_batch wrapper previously had no test coverage. This PR adds:

  • test_send_message_batch — happy path: asserts the producer span per entry, full span attributes, and context propagation injection.
  • test_send_message_batch_all_failed — regression test reproducing the KeyError when the response has no Successful key.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 26, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@ferencjuhasz ferencjuhasz requested a review from a team as a code owner June 26, 2026 08:00
@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Jul 1, 2026
@ferencjuhasz ferencjuhasz force-pushed the boto3sqs-fix-send-batch-successful-keyerror branch from c6b4af7 to 9d97aff Compare July 2, 2026 08:01
@xrmx

xrmx commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@ferencjuhasz no need to rebase the changes, we'll take care of that at merge time, thanks!

@ferencjuhasz

Copy link
Copy Markdown
Author

sorry about that, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

2 participants