Skip to content

feat(boto3): Add ServiceExtension class - #7536

Draft
pabloDeputter wants to merge 10 commits into
pablo/add-boto3-response-retry-error-attributesfrom
pablo/add-boto3-service-extension-class
Draft

pabloDeputter wants to merge 10 commits into
pablo/add-boto3-response-retry-error-attributesfrom
pablo/add-boto3-service-extension-class

Conversation

@pabloDeputter

Copy link
Copy Markdown
Member

Description

Adds service-extension support to Boto3Integration. This keeps the generic Boto3 call lifecycle independent of individual AWS services.

  • Adds _ServiceExtension interface for service-specific behavior through _get_span_config(), _get_request_attributes(), and _get_response_attributes(). This allows for custom span operations/origin, request attributes, and response/error attributes. A future method can also inject trace context into service-specific payload, e.g. SQS message attributes.
  • Extensions are lazily imported (not sure whether this actually a good thing). Service modules are only imported on first use and falls back to generic behavior when service is unknown or broken.
  • Generic attributes and errors remain authoritative over service-specific ones.

Issues

Resolves #7477

@pabloDeputter
pabloDeputter added this pull request to stack #7500 September 18, 2026 13:31
@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

130421 passed | ⏭️ 7171 skipped | Total: 137592 | Pass Rate: 94.79% | Execution Time: 445m 23s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +1066
Passed Tests 📈 +1043
Failed Tests
Skipped Tests 📈 +23

All tests are passing successfully.

✅ Patch coverage is 84.75%. Project has 2566 uncovered lines.
✅ Project coverage is 90.25%. Comparing base (a72a791) to head (17d48a0).

Files with missing lines (3)
File Patch % Lines
sentry_sdk/integrations/boto3/_services/registry.py 61.11% ⚠️ 7 Missing and 1 partials
sentry_sdk/integrations/boto3/_instrumentation.py 92.86% ⚠️ 1 Missing and 2 partials
sentry_sdk/integrations/boto3/_services/base.py 88.89% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
+ Coverage    90.20%    90.25%    +0.05%
==========================================
  Files          194       201        +7
  Lines        25888     26320      +432
  Branches      9584      9752      +168
==========================================
+ Hits         23352     23754      +402
- Misses        2536      2566       +30
- Partials      1455      1462        +7

Generated by Codecov Action

Comment thread sentry_sdk/integrations/boto3/_services/registry.py
@pabloDeputter
pabloDeputter removed this pull request from stack #7500 September 18, 2026 14:34
@pabloDeputter
pabloDeputter added this pull request to stack #7539 September 18, 2026 14:35
@pabloDeputter
pabloDeputter force-pushed the pablo/add-boto3-service-extension-class branch from 499dbcc to d9609eb Compare September 18, 2026 15:06
@pabloDeputter
pabloDeputter removed this pull request from stack #7539 September 18, 2026 15:08
@pabloDeputter
pabloDeputter added this pull request to stack #7541 September 18, 2026 15:08
@pabloDeputter
pabloDeputter force-pushed the pablo/add-boto3-service-extension-class branch from d9609eb to ea505d1 Compare September 18, 2026 15:20
Comment on lines +208 to +212
service_op, service_origin = config
if isinstance(service_op, str) and service_op:
span_op = service_op
if isinstance(service_origin, str) and service_origin:
span_origin = service_origin

@sentry-warden sentry-warden Bot Sep 18, 2026

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.

Custom service origin skips streamed request enrichment

When a service extension overrides span origin, streamed spans fail the origin check in _sentry_request_created, so request attributes and _sentrysdk_span are never attached. Please keep the boto3 origin (or update that guard) if origin overrides are supported.

Evidence
  • In _start_client_span, a non-empty service_origin from service_ext.get_span_config(ctx) replaces span_origin and is written to SPANDATA.SENTRY_ORIGIN for streamed spans.
  • _sentry_request_created returns early when the current span is a StreamedSpan whose SPANDATA.SENTRY_ORIGIN is not exactly Boto3Integration.origin.
  • That early return skips _set_request_attributes() and never sets request.context["_sentrysdk_span"].
  • test_service_extension_customizes_client_span only overrides op (("aws.test", None)), so this origin path is untested.
Also found at 1 additional location
  • sentry_sdk/integrations/boto3/_client.py:92-92

Identified by Warden · code-review, find-bugs · JFX-TK2

@pabloDeputter
pabloDeputter force-pushed the pablo/add-boto3-service-extension-class branch 2 times, most recently from 9068e22 to b9071e2 Compare September 21, 2026 15:42
@pabloDeputter
pabloDeputter force-pushed the pablo/add-boto3-service-extension-class branch from b9071e2 to 787cd71 Compare September 21, 2026 16:07
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.

feat(boto3): Add-service extension class

1 participant