Repository navigation
starlette: fix transaction completion with instrumentation disabled - #2778
Merged
Merged
Conversation
Keep the Starlette transaction-ending hook active when explicitly installed APM middleware uses INSTRUMENT=False. Previously, the middleware started transactions but never finished or reported them. Restrict instrumentation to the lifecycle hook so other library integrations remain disabled. Preserve transaction context through outer error handling and streaming responses.
🤖 GitHub commentsJust comment with:
|
🔍 Preview links for changed docs |
Elastic Docs Style Checker (Vale)Summary: 1 suggestion found 💡 Suggestions (1): Optional style improvements. Apply when helpful.
The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the Starlette/FastAPI transaction-lifecycle fix.
No open issues 🎉
What changed in this PR
This PR fixes unfinished HTTP transactions in the Elastic APM Python agent when explicitly installed Starlette/FastAPI middleware uses INSTRUMENT=False.
Changes:
- Keep the transaction-ending lifecycle hook active while leaving library instrumentation disabled.
- Add regression tests for successful requests, error handling, streaming responses, and disabled-agent behavior.
- Document the framework-hook exception to
INSTRUMENT=False.
| File | Description |
|---|---|
tests/contrib/asyncio/starlette_instrument_disabled_tests.py |
Add transaction completion and instrumentation-setting regression tests. |
elasticapm/instrumentation/control.py |
Allow instrumentation to be restricted to selected classes. |
elasticapm/contrib/starlette/__init__.py |
Install only the lifecycle hook when library instrumentation is disabled. |
docs/reference/configuration.md |
Explain the retained Starlette/FastAPI lifecycle hook. |
Review effort: Balanced
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.
What does this pull request do?
Keep the Starlette transaction-ending hook active when explicitly installed APM middleware uses INSTRUMENT=False. Previously, the middleware started transactions but never finished or reported them.
Restrict instrumentation to the lifecycle hook so other library integrations remain disabled. Preserve transaction context through outer error handling and streaming responses.
Related issues