Commit f537771
feat(arcade-serve): optional pluggable telemetry library integration (#862)
## Summary
Adds an opt-in integration with a pluggable telemetry library so
deployments that need richer observability (Sentry, request correlation,
structured logging) can swap it in without forking `arcade-serve`. When
the library isn't installed, behavior is identical to today.
- New bridge module
`libs/arcade-serve/arcade_serve/fastapi/_arcade_telemetry.py` — guarded
`importlib` check, no new declared dependency.
- `OTELHandler.instrument_app()` delegates global OTel
tracer/meter/logger provider setup to the optional library when
available, then still attaches the FastAPI / HTTPX / aiohttp / Requests
auto-instrumentors against whatever providers are set. Falls back to the
built-in OTLP exporter path otherwise.
- `OTELHandler.__init__` accepts `service_name` / `service_version` so
the resource identity matches the MCP server's configured name/version
instead of the hard-coded `"worker"`.
- `create_arcade_mcp()` registers the library's `CorrelationMiddleware`
when present, so `X-Request-Id` is propagated through the request
lifecycle.
- `arcade-serve` patch → minor version bump (3.2.5 → 3.3.0).
## Why
`OTELHandler` is currently a hard-coded OTLP exporter setup. Anyone who
wants Sentry, request correlation, or non-OTLP destinations either
monkey-patches it or runs a fork. This makes that integration a one-line
install: drop a wheel into the venv and `OTELHandler` defers to it
transparently. Nothing changes for the default install.
## Behavior
| Scenario | Provider setup | Auto-instrumentation | Middleware |
|---|---|---|---|
| Default install (no telemetry lib) | `OTELHandler`'s built-in OTLP
exporters (unchanged) | FastAPI / HTTPX / aiohttp / Requests | None
added |
| Telemetry lib installed | Library's `new_telemetry(...)` | FastAPI /
HTTPX / aiohttp / Requests (against global providers) | Library's
`CorrelationMiddleware` |
| `otel_enable=False` | Nothing initializes | Nothing | None added |
The two providers can't coexist (both set global OTel providers —
last-writer-wins), so when the optional library is present it fully owns
provider setup.
## Test plan
- [x] `uv run pytest libs/tests/worker/` — 14 tests pass, including 7
new ones covering both code paths (library absent + simulated-present
via `sys.modules` monkeypatch).
- [x] `uv run pytest libs/tests/worker/ libs/tests/arcade_mcp_server/` —
full sweep: 1429 passing.
- [x] `mypy arcade_serve` clean.
- [x] `mypy arcade_mcp_server` clean.
- [x] `pre-commit` (ruff + ruff-format + guards) clean.
## Notes for reviewers
- The bridge module is the **only** file that touches
`arcade_telemetry`. Every other call site goes through `is_available()`
/ `init_providers()` / `correlation_middleware_cls()` / `shutdown()`.
- No `optional-dependencies` extra is declared in `pyproject.toml` — the
integration is purely runtime-detected. (An extra was attempted but
breaks `uv sync` since the target library isn't published to PyPI.)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes global OpenTelemetry provider initialization and MCP
middleware ordering when OTel and arcade-telemetry are both enabled;
default installs are unchanged but observability behavior can shift for
deployments that add the optional library.
>
> **Overview**
> Adds a **runtime-detected** bridge to optional `arcade-telemetry` so
richer observability (e.g. Sentry, request correlation) can be enabled
by installing a wheel, with **no change** when the library is absent.
>
> **`OTELHandler`** now accepts **`service_name`** /
**`service_version`** (MCP passes configured server identity instead of
a hard-coded `"worker"`). When `arcade-telemetry` is importable, global
tracer/meter/logger setup goes through **`new_telemetry`** (and optional
loguru wiring); FastAPI/HTTPX/aiohttp/Requests instrumentors still
attach against whatever global providers are set. If the library is
missing or opts out (`None` handle), behavior stays on the **built-in
OTLP exporter** path; **`shutdown`** routes to the telemetry handle when
delegation was used.
>
> **`create_arcade_mcp`** registers **`CorrelationMiddleware`** from
arcade-telemetry when OTel is enabled and the class is available, added
**last** so `X-Request-Id` context is set before other middleware runs.
>
> New **`_arcade_telemetry`** module isolates all `importlib` touches;
**`arcade-serve`** bumps **3.2.5 → 3.3.0**. Tests cover delegate vs
built-in paths and MCP middleware gating.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
e753a00. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7b7387b commit f537771
4 files changed
Lines changed: 420 additions & 21 deletions
File tree
- libs
- arcade-mcp-server/arcade_mcp_server
- arcade-serve/arcade_serve/fastapi
- tests/worker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| 163 | + | |
| 164 | + | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
| |||
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
211 | 224 | | |
212 | 225 | | |
213 | 226 | | |
| |||
Lines changed: 93 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
52 | 63 | | |
53 | 64 | | |
54 | 65 | | |
55 | 66 | | |
| 67 | + | |
56 | 68 | | |
57 | 69 | | |
58 | 70 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
75 | 81 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
79 | 117 | | |
80 | 118 | | |
81 | 119 | | |
| |||
152 | 190 | | |
153 | 191 | | |
154 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
155 | 197 | | |
156 | 198 | | |
157 | 199 | | |
0 commit comments