Skip to content

fix(aws-lambda): Only set messaging.batch.message_count for messaging batches - #8161

Closed
ansh-rohilla wants to merge 1 commit into
getsentry:masterfrom
ansh-rohilla:fix/aws-lambda-messaging-batch-message-count-8078
Closed

ansh-rohilla wants to merge 1 commit into
getsentry:masterfrom
ansh-rohilla:fix/aws-lambda-messaging-batch-message-count-8078

Conversation

@ansh-rohilla

Copy link
Copy Markdown

Description

Previously, messaging.batch.message_count was set unconditionally on AWS Lambda streaming spans, defaulting to 1 for any non-list event (HTTP, S3, etc.) and len(event) for top-level lists. Moreover, SQS and SNS deliveries in AWS Lambda come as a dictionary with a Records list, so a batch of 10 messages incorrectly reported 1.

This PR:

  • Adds _get_messaging_batch_count(aws_event) to identify recognized messaging services (AWS SQS and SNS) by checking whether Records is present and belongs to SQS or SNS.
  • Only sets messaging.batch.message_count on the span when the invocation event is a recognized messaging batch (SQS/SNS).
  • Ensures batch_size (and consequently scope.set_tag("batch_size", ...) and scope.set_tag("batch_request", True)) reflects the number of records for SQS and SNS events.
  • Updates existing non-messaging tests and adds new unit tests verifying SQS, SNS, S3, DynamoDB, Kinesis, HTTP, and top-level list handling.

Issues

@ansh-rohilla
ansh-rohilla requested a review from a team as a code owner October 29, 2026 13:14
@pabloDeputter

Copy link
Copy Markdown
Contributor

Thanks for picking this up! Closing this for now, since we aren't sure yet how we're gonna implement this.

For now there the new tests seem to test private helpers as well as mocks; it would be better to e.g. parameterize test_span_streaming_no_error() and drop the new test_aws_lambda_messaging.py file.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(aws-lambda): Only set messaging.batch.message_count for messaging batches

2 participants