Skip to content

feat(otel): move away from contrib module#4691

Merged
cofin merged 3 commits into
litestar-org:mainfrom
cofin:feat/otel-plugin
May 9, 2026
Merged

feat(otel): move away from contrib module#4691
cofin merged 3 commits into
litestar-org:mainfrom
cofin:feat/otel-plugin

Conversation

@cofin

@cofin cofin commented Apr 13, 2026

Copy link
Copy Markdown
Member

Moves the OpenTelemetry plugin from litestar.contrib.opentelemetry to its permanent home at litestar.plugins.opentelemetry. The contrib directory is removed entirely on this branch — there's no shim here.

A few things ride along:

The deprecation shim at litestar.contrib.opentelemetry (with its DeprecationWarning) has been split out to a follow-up PR targeting v2 — that's where 2.x users actually need the migration window before 3.0 GA. This PR is purely the move plus the bug fixes and parity work.

Fixes #4468
Fixes #4466


📚 Documentation preview 📚: https://litestar-org.github.io/litestar-docs-preview/4691

@cofin
cofin requested review from a team, JacobCoffee and provinzkraut as code owners April 13, 2026 15:47
@github-actions github-actions Bot added area/docs This PR involves changes to the documentation area/middleware This PR involves changes to the middleware area/private-api This PR involves changes to the privatized API size: medium type/feat pr/internal labels Apr 13, 2026
@cofin cofin changed the title feat(otel): move to plugins, fix bugs #4468 and #4466, add upstream parity feat(otel): move away from contrib folder structure Apr 13, 2026
@cofin cofin changed the title feat(otel): move away from contrib folder structure feat(otel): move away from contrib module Apr 13, 2026
@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.42%. Comparing base (94468a0) to head (0543f3d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4691      +/-   ##
==========================================
+ Coverage   67.40%   67.42%   +0.01%     
==========================================
  Files         292      292              
  Lines       15013    15022       +9     
  Branches     1686     1686              
==========================================
+ Hits        10119    10128       +9     
  Misses       4758     4758              
  Partials      136      136              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cofin
cofin force-pushed the feat/otel-plugin branch 2 times, most recently from 14ee32a to bb0d601 Compare April 13, 2026 20:48

@JacobCoffee JacobCoffee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm , @provinzkraut ?

Comment thread litestar/middleware/_utils.py
Comment thread litestar/plugins/opentelemetry/_utils.py
@cofin
cofin force-pushed the feat/otel-plugin branch from ec9567b to 3215ee2 Compare April 25, 2026 20:45
@cofin
cofin enabled auto-merge (squash) April 25, 2026 21:02
@cofin
cofin force-pushed the feat/otel-plugin branch from 3215ee2 to b99976c Compare April 25, 2026 21:48
@provinzkraut

Copy link
Copy Markdown
Member

This seems to be targeting the wrong branch. It's deprecating things to be removed in 3.0, but it's also targeting the 3.0 branch. Should be targeting the v2 branch, and then a follow-up PR made into main that does the removal

@cofin
cofin force-pushed the feat/otel-plugin branch 4 times, most recently from 1df4b4a to 2aa4a1a Compare April 26, 2026 16:05
@cofin
cofin force-pushed the feat/otel-plugin branch from 2aa4a1a to 8bf4c4f Compare April 26, 2026 18:11
@cofin

cofin commented Apr 26, 2026

Copy link
Copy Markdown
Member Author

@provinzkraut deprecation notices removed and will be bundled in a separate PR.

@provinzkraut

Copy link
Copy Markdown
Member

@cofin if this is now intentionally targeting main (i.e. v3.0), it should include a changelog entry

@cofin

cofin commented May 9, 2026

Copy link
Copy Markdown
Member Author

@provinzkraut merge conflicts resolved and changelog entry added.

@cofin
cofin merged commit e0204f0 into litestar-org:main May 9, 2026
25 checks passed
cofin added a commit that referenced this pull request May 11, 2026
…ns.minijinja (#4760)

Moves the MiniJinja template engine integration from `litestar.contrib.minijinja` to `litestar.plugins.minijinja`, and removes the contrib path on `main`. A follow-up PR onto `v2` will add a deprecation shim covering both public and private symbols. Same shape as the OTel split (#4691 + #4759) and the repository split (#4735 + #4758).

`litestar/plugins/flash.py` lazily imports the private `_transform_state` from MiniJinja, so any deprecation shim has to forward private symbols. That diagnosis came from @xronocode's audit in #4754; this PR preserves it by migrating flash.py before deleting contrib, so every intermediate commit keeps the dependency graph valid.

Salvages the contrib tests into `tests/unit/test_plugins/test_minijinja.py` (98% coverage), migrates every internal call site, and adds `docs/reference/plugins/minijinja.rst`.

Closes #4718.

Co-authored-by: xronocode <myevdokimov@gmail.com>
cofin added a commit that referenced this pull request May 11, 2026
…4764)

Moves the Mako template engine integration from `litestar.contrib.mako` to `litestar.plugins.mako`, and removes the contrib path on `main`. A follow-up PR onto `v2` will add a deprecation shim, giving 2.x users a migration window. Same shape as the OTel split (#4691 + #4759) and the repository split (#4735 + #4758).

Implementation reference: PR #4753 by @xronocode. Every commit carries a co-author trailer.

Salvages the contrib tests into `tests/unit/test_plugins/test_mako.py`, migrates every internal call site (csrf middleware, flash, template suite), and adds `docs/reference/plugins/mako.rst`.

Closes #4717.

Co-authored-by: xronocode <myevdokimov@gmail.com>
cofin added a commit that referenced this pull request May 13, 2026
…#4762)

Moves the Jinja2 template engine integration from `litestar.contrib.jinja` to `litestar.plugins.jinja`, and removes the contrib path on `main`. A follow-up PR onto `v2` will add a deprecation shim, giving 2.x users a migration window. Same shape as the OTel split (#4691 + #4759) and the repository split (#4735 + #4758).

Implementation reference: PR #4752 by @xronocode. Every commit carries a co-author trailer.

Salvages the contrib tests into `tests/unit/test_plugins/test_jinja.py`, migrates every internal call site (csrf middleware, flash, template suite, htmx examples), and adds `docs/reference/plugins/jinja.rst`.

Closes #4716.

Co-authored-by: xronocode <myevdokimov@gmail.com>
cofin added a commit that referenced this pull request May 14, 2026
…ib namespace (#4759)

This moves the OpenTelemetry integration to `litestar.plugins.opentelemetry` and turns `litestar.contrib.opentelemetry` into a deprecation shim. The same move landed on main as #4691; this is the v2 side, so 2.x users get both a real migration target on their current version and a `DeprecationWarning` pointing them at it. They can update imports while still on 2.x and upgrade cleanly to 3.0.0.

Three symbols are covered: `OpenTelemetryConfig`, `OpenTelemetryInstrumentationMiddleware`, and `OpenTelemetryPlugin`. The contrib location — which was the real implementation on v2 until now — becomes a thin PEP 562 `__getattr__` shim that re-exports from the plugin namespace.

```python
# before
from litestar.contrib.opentelemetry import OpenTelemetryPlugin

# after
from litestar.plugins.opentelemetry import OpenTelemetryPlugin
```

Two upstream bug fixes ride along with the move:

- A `route_handler is None` guard in the middleware helper, fixing a `KeyError` when the OTel middleware runs as the outermost layer before route resolution (#4468)
- Corrected client request/response hook signatures — three params instead of two, matching `opentelemetry-instrumentation-asgi` (#4466)

The config also exposes `tracer` and `http_capture_headers_*` fields that #4691 added on main.

Tests split cleanly: `tests/unit/test_contrib/test_opentelemetry.py` is now the deprecation suite (each access fires `DeprecationWarning` and resolves to the same object as the plugin namespace), and `tests/unit/test_plugins/test_opentelemetry.py` carries the behavior tests for the new namespace.

Deprecated in 2.22.0, removed in 3.0.0. Changelog entry added under the new 2.22.0 block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs This PR involves changes to the documentation area/middleware This PR involves changes to the middleware area/private-api This PR involves changes to the privatized API pr/internal size: medium type/feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: KeyError: 'route_handler' in all routes when setting exclude_opt_key in OpenTelemetryConfig Bug: OpenTelemetryHookHandler has the wrong type

3 participants