Raise opentelemetry-sdk ceiling to <1.44.0 (allow 1.43)#2042
Conversation
logfire pinned `opentelemetry-sdk<1.43.0`, which transitively blocked `opentelemetry-instrumentation-fastapi 0.64b0` — the release containing the fix for the FastAPI >=0.137 `_IncludedRouter` regression that 500s every CORS preflight (open-telemetry/opentelemetry-python-contrib#4700). Raise the upper bound on `opentelemetry-sdk` and `opentelemetry-exporter-otlp-proto-http` to `<1.44.0` so the 1.43.0 line (and fastapi-instrumentation 0.64b0) can be installed. Closes pydantic#2041 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This is the key problem |
OpenTelemetry 1.43 changed the `service.instance.id` resource attribute from the 32-char `uuid4().hex` form to a dashed UUID4. The TestExporter normaliser only recognised the hex form, so on 1.43 a random UUID leaked into every resource snapshot. Match the dashed form too and normalise it to the same fixed value, keeping all existing snapshots valid on both versions. Also relax `test_max_body_size_bytes`: the exact serialised body size depends on the OTel version (897045 on 1.42, 897108 on 1.43), so assert the message shape via a regex rather than a hardcoded byte count. Verified the affected tests pass on both opentelemetry-sdk 1.42.1 and 1.43.0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| return 1234 | ||
| if name == 'service.instance.id': | ||
| if re.match(r'^[0-9a-f]{32}$', value): | ||
| # OpenTelemetry <=1.42 set this to `uuid4().hex` (32 hex chars); 1.43+ uses the |
There was a problem hiding this comment.
No, otel didn't set this before at all, logfire did. This points to the need for a change in config.py, not tests.
The otel change is here: https://github.com/open-telemetry/opentelemetry-python/pull/5259/changes#diff-d2c46fd8da8afdf67c6ad3dd42b0a243c5049f3c720d9bb3351f1d5522338b06R472
The spec is here: https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/#service-instance-id
Also see the docs: https://pydantic.dev/docs/logfire/reference/sql/#service_instance_id
The otel change is causing a change in the documented logfire behaviour. logfire generates a new random UUID for each call to logfire.configure(), whereas it looks like otel holds onto a stable global value. A decision needs to be made about this.
cc @dmontagu who was recently involved in code changes in this area.
There was a problem hiding this comment.
We have two options:
- Defer to OTel — drop our fallback, update docs
- Preserve current behaviour — re-assert our own id above OTel's detector while still letting OTEL_RESOURCE_ATTRIBUTES/user detectors win.
Closes #2041
Summary
logfire pins
opentelemetry-sdk<1.43.0(and the matchingopentelemetry-exporter-otlp-proto-http). That ceiling transitively blocksopentelemetry-instrumentation-fastapi 0.64b0, which requiresopentelemetry-sdk>=1.43and contains the fix for the FastAPI ≥0.137_IncludedRouterregression —_get_route_details()raisesAttributeError, 500-ing every CORS preflight (OPTIONS) request (open-telemetry/opentelemetry-python-contrib#4700).Anyone on
logfire.instrument_fastapi()is therefore effectively pinned to FastAPI<0.137.This bumps the upper bound to
<1.44.0so the 1.43.0 line (and fastapi-instrumentation0.64b0) can be installed.Verification
Installed the exact combination from the issue (fastapi 0.138.x + opentelemetry-sdk 1.43.0 + opentelemetry-instrumentation-fastapi 0.64b0) and ran the relevant suites:
tests/otel_integrations/test_fastapi.py,test_starlette.py,test_asgi.py→ all pass (22).Test robustness for 1.43 (included in this PR)
OTel 1.43 makes two output changes that only surface in tests, addressed so CI stays green whether the lock resolves 1.42 or 1.43:
service.instance.idis now a dashed UUID4 on the default resource (was the 32-charuuid4().hexform in ≤1.42). TheTestExporternormaliser only recognised the hex form, so a random UUID leaked into every resource snapshot. Fixed centrally inlogfire/_internal/exporters/test.pyby normalising the dashed form to the same fixed value — no snapshot edits needed, and it works on both versions.test_max_body_size_bytesnow asserts the message shape via a regex instead of a hardcoded byte count.Both fixes were verified against
opentelemetry-sdk1.42.1 and 1.43.0 (affected tests pass on each).🤖 Generated with Claude Code