Skip to content

fix: lazy per-protocol OTLP exporter imports so unused transports can't break the SDK - #2

Merged
oasisk merged 5 commits into
mainfrom
fix/lazy-exporter-imports
Jul 28, 2026
Merged

fix: lazy per-protocol OTLP exporter imports so unused transports can't break the SDK#2
oasisk merged 5 commits into
mainfrom
fix/lazy-exporter-imports

Conversation

@oasisk

@oasisk oasisk commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Problem

A version-drifted opentelemetry-exporter-otlp-proto-grpc install (1.40.0 alongside opentelemetry-sdk 1.25.0) made the module-level gRPC exporter imports in client.py raise ImportError — taking down the entire package, including for http/protobuf users who never touch gRPC. In a fail-open consumer (the Claude Code tracing hook) this silently disabled reporting for two months.

Version pins alone can't prevent this: the OTLP exporters already declare opentelemetry-sdk~=1.x lockstep, yet pip install --user paths can still bypass resolver guarantees.

Fix (OTEL-distro / dd-trace-py pattern)

  • Lazy per-protocol exporter imports: client.py no longer imports any OTLP exporter at module top. Each initialize_* imports only the configured protocol's exporter at init time — a broken transport you don't use can never break you.
  • Actionable errors: when the needed transport fails to import, the ImportError names the likely version drift, gives the reinstall command, and lists every installed opentelemetry-* version.
  • gRPC is now an optional extra: pip install openobserve-telemetry-sdk[grpc] (matches Splunk/Honeycomb OTEL distros; also drops the heavy grpcio chain from core installs). All OTEL deps get <2.0 upper bounds.
  • Regression tests: tests/test_broken_transport.py poisons the gRPC exporter modules and asserts the package still imports, HTTP tracing still initializes, and gRPC users get a clear error pointing at the [grpc] extra.

Breaking change

protocol="grpc" users must now install the [grpc] extra. HTTP users (the default) are unaffected.

Testing

  • All 34 tests pass (python -m pytest tests/)
  • Live-verified end-to-end: hook → refactored SDK → spans landed in an OpenObserve traces stream

oasisk added 2 commits July 28, 2026 14:42
…'t break the SDK

A drifted opentelemetry-exporter-otlp-proto-grpc install (1.40.0 against
opentelemetry-sdk 1.25.0) made the module-level gRPC exporter imports in
client.py raise ImportError, taking down the whole package for
http/protobuf users who never touch gRPC.

Following the OTEL-distro pattern:
- import exporters lazily at init time, scoped to the configured protocol
- raise an actionable ImportError (names the drift, reinstall command,
  installed opentelemetry-* versions) when the needed transport is broken
- move the gRPC exporter to an optional [grpc] extra; add <2.0 bounds
- add regression tests that poison the gRPC modules and assert the
  package imports, HTTP tracing works, and grpc users get a clear error
….2.0

- dev extra now installs opentelemetry-exporter-otlp-proto-grpc since the
  test suite mock.patches the gRPC transport (clean 'pip install -e .[dev]'
  previously broke the gRPC tests)
- README: drop the stale 'both protocols included in all installations'
  claim, document the [grpc] extra in Installation and the gRPC protocol
  section
- bump version to 0.2.0 for the breaking [grpc]-extra change
@oasisk
oasisk requested a review from haohuaijin July 28, 2026 12:39
@oasisk
oasisk merged commit 69b3d25 into main Jul 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants