Repository navigation
distro: don't require grpc to be importable - #666
Merged
Merged
Conversation
The operator image ships cp312 grpcio, so on Python 3.13 apps importing grpc fails and the distro failed at module load, even though the operator exports via http/protobuf. Make the grpc exporter imports optional and only set the grpc user agent channel option when grpc is available. Refs elastic#653
xrmx
reviewed
Oct 23, 2026
There was a problem hiding this comment.
🟢 Approval recommended
The focused fallback preserves existing exporter behavior and includes regression coverage for configuration without gRPC.
No open issues 🎉
What changed in this PR
Allows the distro to configure HTTP/protobuf exporters when gRPC cannot be imported, addressing the gRPC-related operator injection failure on mismatched Python versions. The separate uuid_utils dependency remains outside this PR’s scope.
Changes:
- Guards gRPC exporter imports and adds gRPC user-agent options only when those imports succeed.
- Adds a regression test verifying HTTP-only SDK configuration and EDOT user-agent headers when gRPC is unavailable.
| File | Description |
|---|---|
tests/distro/test_distro.py |
Tests HTTP-only configuration with gRPC imports blocked. |
src/elasticotel/distro/__init__.py |
Makes gRPC imports and exporter options conditional. |
Review effort: Balanced
xrmx
reviewed
Oct 23, 2026
Doing the optional grpc import in _configure with try/except/else lets pyright see the exporters are bound where they are used, so we don't need a None sentinel for _USER_AGENT_HEADER_VALUE or type: ignore comments. Annotate exporter_args_map so the grpc entries can be added.
xrmx
approved these changes
Oct 26, 2026
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?
Makes the distro work when
grpcis unavailable (e.g. missing / mismatched binary extension), so configuring withhttp/protobufstill works.With operator auto-instrumentation, the injected image ships cp312
grpcio. On a Python >3.13 app,grpc._cython.cygrpcfails to import, soelasticotel.distrofailed at module load. Even though operator would export overhttp/protobufanyway.try/except ImportError.channel_optionsuser agent is only added toexporter_args_mapwhen grpc is available. The HTTP exporters still get the EDOT user agent.The change is based on @xrmx's diff in #653. Checked against 1.18.0 plus a pure-Python uuid7 shim on Python 3.13 (amd64 and arm64): the tracer provider is configured and grpc is never imported.
Related issues
Full independence from binary extensions still depends on
uuid_utils, pending open-telemetry/opentelemetry-python-contrib#5207