Skip to content

Leave sentry-sdk's auto-enabling integrations off while Sentry tracing is off - #363

Merged
lesnik512 merged 1 commit into
mainfrom
sentry-auto-enabling-integrations
Oct 28, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
sentry-auto-enabling-integrations

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Closes #313.

While Sentry tracing is off, lite-bootstrap now passes auto_enabling_integrations=False to sentry_sdk.init. sentry-sdk then stops enabling an integration for every installed package it knows (SQLAlchemy, asyncpg, redis, httpx, aiohttp, MCP and the rest). With tracing off, those integrations still open a span and record a breadcrumb for every statement, command or outgoing request. This is the last of the three lean-capture PRs, after #361 (Litestar) and #362 (FastAPI, FastMCP). Their lean capture is what makes this default safe: it reports request errors without a framework integration, and every framework integration is itself auto-enabling.

Changes

  • SentryConfig.sentry_auto_enabling_integrations: bool | None = None. _build_init_params passes is_sentry_auto_enabling_integrations_on() as auto_enabling_integrations. An explicit value wins, and an auto_enabling_integrations in sentry_additional_params still wins over both, through the existing init_params.update.
  • How None resolves:
    • On SentryConfig (Free, FastStream), it follows tracing: off while is_sentry_tracing_requested() is false.
    • On SentryLeanCaptureConfig (Litestar, FastAPI, FastMCP), it follows lean capture: off when lean capture is on, and on when sentry-sdk's framework integration reports request errors. Otherwise sentry_lean_error_capture=False would silently stop request capture, because the framework integration would never be enabled.
  • The default integrations stay, and so does lite-bootstrap's own LoggingIntegration, on both majors. On 3.0.0b2 the default list no longer contains logging, but lite-bootstrap passes its own in integrations, and a test checks that it is active with auto-enabling off.

Departures from the issue

  • Free and FastStream get a rule too. The issue gives the resolution for lean-capture frameworks only. I made None follow tracing on the plain SentryConfig, per the issue's own reasoning ("the default should follow tracing as lean capture does") and its FastStream measurement. Free and FastStream have no framework integration to lose.
  • The "installed by an earlier init" warning now fires only with auto-enabling on. With auto-enabling off, sentry-sdk never lists the framework integration, so one that an earlier sentry_sdk.init installed stays inactive and nothing is reported twice. The two warning tests now set sentry_auto_enabling_integrations=True. A new test pins that, with the default, an earlier-installed integration is neither active nor warned about. The framework docs say the same.
  • No litestar-sqlalchemy-template rerun. It needs that repository and Postgres. Instead, I reran the FastStream publish suite against a Redis 8 container, which measures the same mechanism, an auto-enabled client integration (below).
  • MCPIntegration is now off by default on FastMCP. Report FastAPI and FastMCP errors without StarletteIntegration while tracing is off #362 left it alone, but it is auto-enabling. I compared a failing tool call's event with it on and off. The exception, request and transaction were the same. The only difference was a parent_span_id from its unsampled tool span. The existing "one event per failing tool call" test covers both modes.

Tests

Written first. These failed on main:

  • test_sentry_leaves_auto_enabling_integrations_off_while_tracing_is_off: aiohttp, httpx and redis were active. It also checks that logging is.
  • test_sentry_auto_enabling_integrations_set_explicitly_wins (both cases) and test_sentry_additional_params_auto_enabling_integrations_wins_over_the_field.
  • test_lean_capture_leaves_auto_enabling_integrations_off_and_still_reports, for FastAPI and for Litestar: no auto-enabled integration is active, and a failing request still sends one event with the request attached.
  • test_forced_lean_capture_leaves_auto_enabling_integrations_off_while_tracing_is_on
  • test_fastmcp_lean_capture_leaves_mcp_integration_off

These passed on main and keep the old behaviour where it should stay: tracing on keeps auto-enabling (three ways to request tracing), and sentry_lean_error_capture=False keeps it on FastAPI and Litestar.

The full suite passes, 552 tests at 100% coverage, on sentry-sdk 2.73.0 and 3.0.0b2. ty passes against both, and so do just lint, just adr-check, just docs-build and lychee. floor_smoke.py passes for every target on the newest versions. No floor changes, so I left the floor runs to CI.

Measurement

Per broker.publish to Redis 8 in a local container, on an M2 Mac (CPython 3.14.7, faststream 0.7.8, redis 8.1.0), in µs over lite-bootstrap logging alone, about 136 µs:

scenario 2.73.0 3.0.0b2
sentry, the new default -3.0 -1.7
sentry_auto: sentry_auto_enabling_integrations=True +27.1 +9.5
sentry_noauto: auto_enabling_integrations=False in sentry_additional_params -1.6 -1.4

The baseline's first round ran 11% slower than the other two, so the negative rows are noise. sentry_auto is a new scenario in faststream_suite.py.

Docs

  • configuration.md: a bullet for the field, and a new "Sentry auto-enabling integrations" section. It covers the rule, what the integrations cost with tracing off, what error events lose (SQL, Redis and outgoing-HTTP breadcrumbs, and anything else an auto-enabled integration attaches), and how to keep them: sentry_auto_enabling_integrations=True, or list the wanted integrations in sentry_integrations.
  • performance.md: the "savings applied for you" paragraph adds this one and what it costs.
  • fastapi.md and litestar.md: the earlier-init warning applies only with auto-enabling on. fastmcp.md: MCPIntegration is now off with lean capture.
  • benchmarks/README.md §8d: the old Sentry row is relabelled "1.x defaults", and the rerun is added.

Breaking changes

For services with Sentry and tracing off: SQL, Redis, httpx and aiohttp breadcrumbs stop, and so does anything else an auto-enabled integration added to error events, including MCPIntegration on FastMCP. Set sentry_auto_enabling_integrations=True to get them back, or list the integrations you want in sentry_integrations.

Open question

sentry_lean_error_capture=False together with an explicit sentry_auto_enabling_integrations=False, and no framework integration in sentry_integrations, leaves nothing reporting request errors. That only happens when both options are set by hand, and lite-bootstrap doesn't warn about it. I left a warning out of this PR, since the issue doesn't ask for one.

…g is off

Adds sentry_auto_enabling_integrations, passed as auto_enabling_integrations.
None follows tracing on SentryConfig, and follows lean error capture on the
Litestar, FastAPI and FastMCP configs, whose framework integrations are
auto-enabling themselves.

Closes #313.
@lesnik512
lesnik512 merged commit 05346fb into main Oct 28, 2026
37 checks passed
@lesnik512
lesnik512 deleted the sentry-auto-enabling-integrations branch October 28, 2026 20:42
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.

Default sentry_auto_enabling_integrations to False together with lean capture

1 participant