Skip to content

feat(boto3): Add SQS extension - #8137

Open
pabloDeputter wants to merge 7 commits into
major/3.0from
pablo/boto3-add-sqs-extension
Open

pabloDeputter wants to merge 7 commits into
major/3.0from
pablo/boto3-add-sqs-extension

Conversation

@pabloDeputter

Copy link
Copy Markdown
Contributor

Description

Adds the SQS extension, now SQS MESSAGING operations become queue.* spans so they show up in the Queues insight; all other SQS APIs stay rpc:

  • SendMessage, SendMessageBatch: queue.publish, kind producer (default is client), named send <queue>
  • ReceiveMessage: queue.receive, named receive <queue>
  • DeleteMessage, DeleteMessageBatch: queue.settle, named settle <queue>

Adds the following attributes:

  • messaging.system (aws_sqs), messaging.operation.type and messaging.operation.name on the messaging APIs (all from OTel)
  • messaging.batch.message_count on batch APIs: submitted entries for send/delete, returned messages for receive
  • messaging.message.id on SendMessage, and on ReceiveMessage when exactly one message is returned
  • aws.sqs.queue.url and messaging.destination.name (queue name) on every API with QueueUrl; destination name also from QueueName and SourceArn

Issues

Resolves #7572 & PY-2803

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 57980 passed | ⏭️ 3008 skipped | Total: 60988 | Pass Rate: 95.07% | Execution Time: 151m 5s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -83689
Passed Tests 📉 -79241
Failed Tests —
Skipped Tests 📉 -4448

All tests are passing successfully.

✅ Patch coverage is 100.00% (63 of 63 changed executable lines covered; target 80%).
Project statement coverage is 90.37% (up 0.07 percentage points from base (df16ce5) to head (f6c8099)).

Changed files with executable lines (4)
File Patch coverage Changed executable lines
sentry_sdk/integrations/boto3/_services/sqs.py 100.00% 49/49 covered; partial branches: 61, 71
sentry_sdk/consts.py 100.00% 8/8 covered
sentry_sdk/integrations/boto3/_instrumentation.py 100.00% 4/4 covered
sentry_sdk/integrations/boto3/_services/base.py 100.00% 2/2 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #8137       +/-##
==========================================
+ Coverage    90.30%    90.37%    +0.07%
==========================================
  Files          203       199        -4
  Tracked lines     26933     21357     -5576
  Branches     10058      7396     -2662
==========================================
- Hits         24321     19300     -5021
+ Misses        2612      2057      -555
+ Partials      1518      1235      -283

Generated by Coverage Action

@pabloDeputter
pabloDeputter force-pushed the pablo/boto3-add-sqs-extension branch from 5f4f1d0 to 0f90423 Compare October 27, 2026 16:59
@pabloDeputter
pabloDeputter marked this pull request as ready for review October 29, 2026 09:03
@pabloDeputter
pabloDeputter requested a review from a team as a code owner October 29, 2026 09:03
sentrivana added a commit that referenced this pull request Oct 29, 2026
### Description

Removes `AwsCallContext.service_id_hyphenized` from
`sentry_sdk/integrations/boto3/_context.py`. It's still computed on
every call (`service_id.hyphenize()`), but on `major/3.0` nothing reads
it.

It had two readers. One was the `aws.service_id` span tag, which #7261
("Drop tags auto-set by the SDK") removed. The other was the span name:
#7800 ("align span names with OTel conventions") switched that to
`ctx.service_id`, so the hyphenized value lost its last reader. This
removes the slot, the attribute and the `hyphenize()` call.

**Evidence**
- On `major/3.0`, `git grep -w service_id_hyphenized` matches only the
three lines in `_context.py` that set it up.
- The open boto3 extension PRs against `major/3.0` (#8117 SQS, #8137
Lambda) don't reference it.

On `master`, `service_id_hyphenized` is still used for the span name and
the tag, so this only applies to `major/3.0`.

#### Issues
n/a

<!-- junior-request-attribution:start -->
via **Ivana Kellyer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0BTREZTS2Z%3A1793270559.842119 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0BTREZTS2Z%3A1793270559.842119)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0BTREZTS2Z%3A1793270559.842119/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
attributes[SPANDATA.AWS_SQS_QUEUE_URL] = queue_url

# `https://sqs.eu-north-1.amazonaws.com/123456789012/orders` => ['123456789012', 'orders']
path = unquote(urlsplit(queue_url).path).strip("/").split("/")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is queue_url validated by the library before it's handed to us through ctx.params?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, all parameters used in get_request_attributes() are yet to be validated. QueueUrl is also only checked to be a string, e.g. a non-string 1234 will raise an error at urlsplit and is captured at boto3/_instrumentation.py=180, so all SQS request attributes are dropped. Then get_span_name() at boto3/_instrumentation.py:183 will raise an error (if it's one of the API operations in _MESSAGING_OPERATIONS), which is captured again at boto3/_client.py:92, so no span is sent. Other operations still send the span, just without any SQS attributes.

@pabloDeputter pabloDeputter Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did fix this partly in #8142, by adding another guard to get_span_name() at boto3/_instrumentation.py=183, so the span is sent, but still has no request attributes.

So I added some more precautions (c640799) in get_span_name() so that it doesn't take the operation type from attributes anymore, and the queue_url parsing is also guarded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary for whoever resolves this thread. botocore only checks that QueueUrl is a string, so this PR no longer relies on its shape:

  • c640799 (this PR): get_span_name() takes the operation type from _MESSAGING_OPERATIONS instead of the request attributes, and the URL parsing in get_request_attributes() sits inside capture_internal_exceptions(). A malformed URL now only loses the destination name and account ID, and the span is still sent.
  • c73d9ba (feat(boto3): Add SNS extension #8142): a second capture_internal_exceptions() guard around get_span_name() in _instrumentation.py.

I merged major/3.0 into this branch today, and the boto3 tests still pass.

pabloDeputter and others added 2 commits October 30, 2026 13:55
- stop reading operation type from attributes in `get_span_name()` so that failure in `get_request_attributes()` can't make this fail as well
- wrap URL parsing in `get_request_attributes()` so failure just loses the attributes that come from url
…sqs-extension

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

@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.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f6c8099. Configure here.

attributes[SPANDATA.MESSAGING_BATCH_MESSAGE_COUNT] = len(
ctx.params["Entries"]
)
return attributes

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SQS attribute collection is not isolated

Low Severity

get_request_attributes now does several unguarded extractions in one shot, while the caller wraps the whole method. Botocore has not validated params yet, so a bad Entries value or a malformed SourceArn/DestinationArn raises and discards already-parsed QueueUrl, destination, messaging.system, and producer kind. Sibling services still isolate _get_aws_arn_attributes, and the previous SQS code did too.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f6c8099. Configure here.

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.

2 participants