|
| 1 | +--- |
| 2 | +summary: Add an `opentelemetry_exporter_protocol` config (grpc|http, default grpc) and an `otl-http` extra (opentelemetry-exporter-otlp-proto-http, no grpcio) so OTLP trace export works on free-threaded Python; repoint `otl` to the grpc exporter package. |
| 3 | +--- |
| 4 | + |
| 5 | +# Design: OTLP HTTP exporter option (free-threaded OTLP export) |
| 6 | + |
| 7 | +## Summary |
| 8 | + |
| 9 | +The `otl` extra is the last observability surface with no free-threaded story: |
| 10 | +its OTLP exporter goes over gRPC, which needs `grpcio`, which ships no |
| 11 | +free-threaded wheels. OpenTelemetry also offers an **HTTP/protobuf** exporter |
| 12 | +(`requests` + `protobuf`, no grpcio) that talks to the same collectors. Add an |
| 13 | +`opentelemetry_exporter_protocol` config knob (default `"grpc"`, unchanged |
| 14 | +behavior) and an `otl-http` extra so a free-threaded service can export traces. |
| 15 | + |
| 16 | +## Motivation |
| 17 | + |
| 18 | +`otl` installs `opentelemetry-exporter-otlp` (a meta package pulling **both** the |
| 19 | +grpc exporter → `grpcio` and the http exporter), so `pip install |
| 20 | +lite-bootstrap[otl]` cannot resolve on a free-threaded interpreter |
| 21 | +([grpc/grpc#38762](https://github.com/grpc/grpc/issues/38762)). The instrument |
| 22 | +hardwired the gRPC exporter. The HTTP exporter |
| 23 | +(`opentelemetry-exporter-otlp-proto-http`) has no `grpcio` dependency (verified: |
| 24 | +`requests`, `opentelemetry-proto`, `googleapis-common-protos`), so it installs |
| 25 | +on ft. This was deferred from the 2026-07-14 free-threading work; picking it up. |
| 26 | + |
| 27 | +## Design |
| 28 | + |
| 29 | +### 1. Config: exporter protocol |
| 30 | + |
| 31 | +```python |
| 32 | +# OpenTelemetryConfig |
| 33 | +opentelemetry_exporter_protocol: typing.Literal["grpc", "http"] = "grpc" |
| 34 | +``` |
| 35 | + |
| 36 | +Default `"grpc"` preserves current behavior exactly. `opentelemetry_insecure` |
| 37 | +applies to gRPC only; for HTTP the endpoint is a full URL |
| 38 | +(`http://collector:4318/v1/traces`) whose scheme carries security — documented, |
| 39 | +not warned (see `decisions/2026-07-19-otlp-http-exporter-shape.md`). |
| 40 | + |
| 41 | +### 2. Two guarded, aliased exporter imports |
| 42 | + |
| 43 | +`import_checker.py`: add |
| 44 | +`is_otlp_http_exporter_installed = _safe_find_spec("opentelemetry.exporter.otlp.proto.http.trace_exporter")` |
| 45 | +alongside the existing `is_otlp_grpc_exporter_installed`. |
| 46 | + |
| 47 | +`opentelemetry_instrument.py`: import each under its own guard, aliased to avoid |
| 48 | +the shared `OTLPSpanExporter` name: |
| 49 | + |
| 50 | +```python |
| 51 | +if import_checker.is_otlp_grpc_exporter_installed: |
| 52 | + from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter as OTLPGrpcSpanExporter |
| 53 | +if import_checker.is_otlp_http_exporter_installed: |
| 54 | + from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter as OTLPHttpSpanExporter |
| 55 | +``` |
| 56 | + |
| 57 | +### 3. Protocol-selecting `bootstrap()` |
| 58 | + |
| 59 | +```python |
| 60 | +if self.bootstrap_config.opentelemetry_endpoint: |
| 61 | + if self.bootstrap_config.opentelemetry_exporter_protocol == "grpc": |
| 62 | + if import_checker.is_otlp_grpc_exporter_installed: |
| 63 | + tracer_provider.add_span_processor( # pragma: no cover (live collector) |
| 64 | + BatchSpanProcessor(OTLPGrpcSpanExporter(endpoint=..., insecure=...))) |
| 65 | + else: |
| 66 | + warnings.warn("… gRPC OTLP exporter is not installed … install lite-bootstrap[otl].", …) |
| 67 | + elif import_checker.is_otlp_http_exporter_installed: |
| 68 | + tracer_provider.add_span_processor( # pragma: no cover (live collector) |
| 69 | + BatchSpanProcessor(OTLPHttpSpanExporter(endpoint=self.bootstrap_config.opentelemetry_endpoint))) |
| 70 | + else: |
| 71 | + warnings.warn("… HTTP OTLP exporter is not installed … install lite-bootstrap[otl-http].", …) |
| 72 | +``` |
| 73 | + |
| 74 | +The exporter-construction lines keep `# pragma: no cover` (need a live |
| 75 | +collector); both missing-exporter warn branches are covered by tests. |
| 76 | + |
| 77 | +### 4. Extras |
| 78 | + |
| 79 | +`pyproject.toml`: repoint `otl` from the meta package to the grpc exporter, and |
| 80 | +add `otl-http`: |
| 81 | + |
| 82 | +```toml |
| 83 | +otl = ["opentelemetry-api", "opentelemetry-sdk", "opentelemetry-exporter-otlp-proto-grpc", "opentelemetry-instrumentation"] |
| 84 | +otl-http = ["opentelemetry-api", "opentelemetry-sdk", "opentelemetry-exporter-otlp-proto-http", "opentelemetry-instrumentation"] |
| 85 | +``` |
| 86 | + |
| 87 | +`otl` users are unaffected functionally (it already defaulted to gRPC and never |
| 88 | +used the http exporter). No framework `*-otl-http` variants — a free-threaded |
| 89 | +framework service composes `[fastapi, otl-http]` and adds its instrumentation |
| 90 | +package if it wants auto-instrumentation. |
| 91 | + |
| 92 | +### 5. CI + proof |
| 93 | + |
| 94 | +Add `otl-http` to both ft legs' extras in `_checks.yml` (proves it resolves on |
| 95 | +3.13t/3.14t). Extend `scripts/ft_smoke.py` to bootstrap an |
| 96 | +`OpenTelemetryInstrument` with `opentelemetry_exporter_protocol="http"` and an |
| 97 | +endpoint, then tear down — proving the http export path constructs on ft with no |
| 98 | +live collector needed. |
| 99 | + |
| 100 | +## Non-goals |
| 101 | + |
| 102 | +- **Framework `*-otl-http` extras.** Avoided to keep the extras matrix small. |
| 103 | +- **Changing the default protocol.** Stays `grpc` for backward compatibility. |
| 104 | +- **An `insecure`-style flag or http:// warning for HTTP.** The URL scheme |
| 105 | + carries security; documented, per the decision file. |
| 106 | + |
| 107 | +## Testing |
| 108 | + |
| 109 | +- Unit (TDD): with `opentelemetry_exporter_protocol="http"` + an endpoint, |
| 110 | + `bootstrap()` constructs the **http** exporter (patch `OTLPHttpSpanExporter`, |
| 111 | + assert called with the endpoint); `"grpc"` still constructs the grpc exporter; |
| 112 | + the http-absent and grpc-absent branches each emit |
| 113 | + `InstrumentDependencyMissingWarning` naming the right extra. |
| 114 | +- ft CI leg installs `otl-http` and `scripts/ft_smoke.py` bootstraps a |
| 115 | + protocol=http instrument on 3.13t/3.14t. |
| 116 | +- `just test` 100% coverage; `just lint-ci` clean. |
| 117 | + |
| 118 | +## Risk |
| 119 | + |
| 120 | +- **`otl` dependency-set change (low × low).** From the `opentelemetry-exporter-otlp` |
| 121 | + meta to `opentelemetry-exporter-otlp-proto-grpc`. Same grpc exporter, minus the |
| 122 | + unused http package; grpc behavior unchanged. Noted in the release note. |
0 commit comments