Skip to content

feat(aws-lambda): Add queue.process spans for messaging triggers - #8223

Draft
sentry-junior[bot] wants to merge 5 commits into
junior/aws-lambda-triggerfrom
junior/aws-lambda-queue-process
Draft

sentry-junior[bot] wants to merge 5 commits into
junior/aws-lambda-triggerfrom
junior/aws-lambda-queue-process

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

For an SQS or SNS delivery, the handler now runs inside a queue.process child span of kind consumer. The span has:

  • messaging.system
  • messaging.operation.type and messaging.operation.name, both process
  • the batch message count
  • the destination name (queue or topic, from the first record)

The span links to each distinct producer context in the records' Sentry message attributes (at most 128 links): SQS messageAttributes, SNS MessageAttributes, and SQS bodies that wrap an SNS notification. This gives an SQS-triggered Lambda a link back to the request that sent the message. It also fills in the processing side of the Queues insight.

This is Pablo's code from pablo/aws-lambda-messaging, moved directly onto trigger detection (#8222). On his branch it sat on top of HTTP and invocation attribute work (PY-3017, PY-3019, PY-3021), which isn't part of the November plan. Moving it needed one hand-made change: in _handler.py I kept the base handler and only wrapped the handler call in the process span, because Pablo's version of that block includes the HTTP status and error.type code from the dropped commits. _trigger.py matches his branch, minus his batch counting for the invocation span and the faas.trigger attribute on the process span (it stays on the invocation span). The process-span tests match his branch. The only tests left out are the ones for the dropped attributes.

test_process_span_error covers a handler that raises.

Open points for review:

Third of three stacked drafts (#8221 → #8222 → this).

Issues

via @dingsdax.

--

View Session [Sentry]

For an SQS, SNS, Kafka, ActiveMQ or RabbitMQ delivery, the handler runs
inside a queue.process child span (kind consumer) with messaging.system,
messaging.operation.type and messaging.operation.name set to process,
the batch message count, and the destination name when all records
share it.

The span links to each distinct producer context found in the records'
Sentry message attributes: SQS messageAttributes, SNS MessageAttributes,
and SQS bodies that wrap an SNS notification.

Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com>
@linear-code

linear-code Bot commented Nov 9, 2026

Copy link
Copy Markdown

PY-3020

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 57719 passed | ⏭️ 2979 skipped | Total: 60698 | Pass Rate: 95.09% | Execution Time: 156m 30s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -83979
Passed Tests 📉 -79502
Failed Tests —
Skipped Tests 📉 -4477

All tests are passing successfully.

❌ Patch coverage is 30.16% (19 of 63 changed executable lines covered; target 80%).
Project statement coverage is 89.91% (down 0.43 percentage points from base (d877f00) to head (feaef1c)).

Changed files with executable lines (3)
File Patch coverage Changed executable lines
sentry_sdk/integrations/aws_lambda/_trigger.py 25.00% 13/52 covered; missed: 113, 114, 117, 120, 121, 122, 127, 128, 129, 132, 134, 139, 140, 141, 142, 143, 144, 145, 147, 148, 149, 150, 151, 153, 154, 155, 156, 157, 158, 160, 165, 166, 167, 169, 170, 171, 174, 179, 181
sentry_sdk/integrations/aws_lambda/_handler.py 28.57% 2/7 covered; missed: 211, 212, 213, 214, 215
sentry_sdk/consts.py 100.00% 4/4 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #8223       +/-##
==========================================
- Coverage    90.34%    89.91%    -0.43%
==========================================
  Files          203       199        -4
  Tracked lines     26931     21486     -5445
  Branches     10058      7442     -2616
==========================================
- Hits         24331     19319     -5012
+ Misses        2600      2167      -433
+ Partials      1517      1240      -277

Generated by Coverage Action

sentry-junior Bot and others added 2 commits November 9, 2026 07:59
…-process

Co-Authored-By: johdax <114897+dingsdax@users.noreply.github.com>

# Conflicts:
#	sentry_sdk/integrations/aws_lambda/_handler.py
#	sentry_sdk/integrations/aws_lambda/_trigger.py
The error is captured, both the process span and the invocation span
are marked as errors, and the exception still reaches the Lambda
runtime.

Co-Authored-By: johdax <114897+dingsdax@users.noreply.github.com>
sentry-junior Bot and others added 2 commits November 9, 2026 12:18
…-process

Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com>
OTel sets faas.trigger on the FaaS span, which already has it. Also make
the producer link cap private, like the other module constants.

Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant