Skip to content

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

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

sentry-junior[bot] wants to merge 8 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. Each link has sentry.link.type: message_origin, like the boto3 receive links from #8145. 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:

  • messaging.message.id on single-message process spans isn't added yet (proposed in PY-3020).
  • The destination name comes from the first record. The alternative is to set it only when all records share it.

Third of three stacked PRs (#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 📊

✅ 58862 passed | ⏭️ 3071 skipped | Total: 61933 | Pass Rate: 95.04% | Execution Time: 156m 55s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -84942
Passed Tests 📉 -80248
Failed Tests —
Skipped Tests 📉 -4694

All tests are passing successfully.

❌ Patch coverage is 25.42% (15 of 59 changed executable lines covered; target 80%).
Project statement coverage is 90.16% (down 0.08 percentage points from base (380eec4) to head (6bd4fd0)).

Changed files with executable lines (2)
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, 149, 151, 152, 153, 154, 155, 157, 162, 163, 164, 165, 166, 168, 173, 174, 175, 177, 178, 179, 182, 187, 189
sentry_sdk/integrations/aws_lambda/_handler.py 28.57% 2/7 covered; missed: 211, 212, 213, 214, 215
Coverage diff
@@            Coverage Diff             @@
##        master     #8223       +/-##
==========================================
- Coverage    90.24%    90.16%    -0.08%
==========================================
  Files          203       200        -3
  Tracked lines     27125     21879     -5246
  Branches     10142      7622     -2520
==========================================
- Hits         24478     19727     -4751
+ Misses        2647      2152      -495
+ Partials      1541      1255      -286

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>
@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 11, 2026 17:47
@sentry-junior
sentry-junior Bot requested a review from a team as a code owner November 11, 2026 17:47

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0291824. Configure here.

A sentry-trace like "-1" parses with no trace_id or parent_span_id,
which became a link to "None". Skip it, as boto3 receive links do.

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