Repository navigation
Leave sentry-sdk's auto-enabling integrations off while Sentry tracing is off - #363
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #313.
While Sentry tracing is off, lite-bootstrap now passes
auto_enabling_integrations=Falsetosentry_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_paramspassesis_sentry_auto_enabling_integrations_on()asauto_enabling_integrations. An explicit value wins, and anauto_enabling_integrationsinsentry_additional_paramsstill wins over both, through the existinginit_params.update.Noneresolves:SentryConfig(Free, FastStream), it follows tracing: off whileis_sentry_tracing_requested()is false.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. Otherwisesentry_lean_error_capture=Falsewould silently stop request capture, because the framework integration would never be enabled.LoggingIntegration, on both majors. On 3.0.0b2 the default list no longer containslogging, but lite-bootstrap passes its own inintegrations, and a test checks that it is active with auto-enabling off.Departures from the issue
Nonefollow tracing on the plainSentryConfig, 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.sentry_sdk.initinstalled stays inactive and nothing is reported twice. The two warning tests now setsentry_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.MCPIntegrationis 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 aparent_span_idfrom 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,httpxandrediswere active. It also checks thatloggingis.test_sentry_auto_enabling_integrations_set_explicitly_wins(both cases) andtest_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_ontest_fastmcp_lean_capture_leaves_mcp_integration_offThese 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=Falsekeeps it on FastAPI and Litestar.The full suite passes, 552 tests at 100% coverage, on sentry-sdk 2.73.0 and 3.0.0b2.
typasses against both, and so dojust lint,just adr-check,just docs-buildand lychee.floor_smoke.pypasses for every target on the newest versions. No floor changes, so I left the floor runs to CI.Measurement
Per
broker.publishto 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:sentry, the new defaultsentry_auto:sentry_auto_enabling_integrations=Truesentry_noauto:auto_enabling_integrations=Falseinsentry_additional_paramsThe baseline's first round ran 11% slower than the other two, so the negative rows are noise.
sentry_autois a new scenario infaststream_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 insentry_integrations.performance.md: the "savings applied for you" paragraph adds this one and what it costs.fastapi.mdandlitestar.md: the earlier-init warning applies only with auto-enabling on.fastmcp.md:MCPIntegrationis 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
MCPIntegrationon FastMCP. Setsentry_auto_enabling_integrations=Trueto get them back, or list the integrations you want insentry_integrations.Open question
sentry_lean_error_capture=Falsetogether with an explicitsentry_auto_enabling_integrations=False, and no framework integration insentry_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.