Skip to content

refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake - #2541

Merged
dan-petty merged 2 commits into
mainfrom
refactor/1319-otlp-exporter-seam
Oct 28, 2026
Merged

dan-petty merged 2 commits into
mainfrom
refactor/1319-otlp-exporter-seam

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

OTLP export goes through one exporter seam, and tests read what the tracer exports from a shared OTLP fake instead of patching its private methods.

  • src/devops_cli/telemetry/exporter.py is the edge between the tracer and the collector. OtlpExporter exports one signal's encoded request (/v1/traces, /v1/metrics, /v1/logs) and probes the collector. HttpOtlpExporter, the real exporter, posts through the egress-checked client (new_http_client, private level), so the telemetry clients that fix(security): the pre-flight resolve paths go, the kept pre-flight checks call vet_addresses, and the docs say every http client is checked at the connect #2437 waits on are on the factory. Each failure has one text: HTTP <status>, "Cannot connect to the collector" or "The collector did not answer in time".
  • The probe posts an empty trace export request, which the collector answers and does not store. It no longer stores a ping span of the service devops-cli-ping.
  • devops-cli sends no OTLP over gRPC. OTEL_EXPORTER_OTLP_PROTOCOL=grpc (or another value that is not http/json or http/protobuf), or with no protocol an endpoint with the grpc scheme or port 4317, fails with an OtlpProtocolError that names the setting. Before, every export to that port failed with only a count. The process tracer keeps the command running with export off, logs one warning, and its probe in devops telemetry status reports the message.
  • OTelTelemetryClient takes an exporter and keeps its executor, dry-run suppression and counters. install_exporter and remove_exporter put an exporter in place of the configured one, with export on; the floor removes it after each test.
  • Deleted: _get_grpc_exporter, _get_http_client, the raw-socket gRPC probe and the protocol attribute. opentelemetry-exporter-otlp-proto-grpc leaves the direct dependencies, and opentelemetry-sdk 1.45.1, which src imports for the MeterProvider, joins them.
  • Tests: FakeCollector in tests/support/fakes/otlp.py, behind the otlp fixture, records each export and gives spans, metric data points and log records as plain values. The contract suite tests/telemetry/test_otlp_exporter_contract.py runs each case on the fake and on HttpOtlpExporter over a loopback receiver. The export tests of tests/test_telemetry_collector_export.py and tests/test_telemetry.py, and every user of the captured fixture, read the fake; tests/support/telemetry_capture.py is deleted. The swallowed-failures ceiling of telemetry/tracer.py falls from 16 to 12.
  • The SDK-built spans and the official protobuf encoders of the 2026-10-08 amendment on refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 are refactor(telemetry): Use OTel SDK encoders for spans, metrics, logs #2536, which builds on this seam.

Closes #1319

Change: openspec/changes/archive/2026-10-28-1319-otlp-exporter-seam/

@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence:

  • Full uv run devops ci in the worktree before the rebase onto 1244cbf: every gate passed; the test gate took 4 m 55 s.
  • After the rebase: the 572 tests of the changed files, tests/test_architectural_invariants.py and tests/invariants/ pass. tests/telemetry/ (34 tests) runs in under 1 s.
  • uv run devops ci fail-to-pass --base origin/main: 0 of the new or changed tests pass on the base. 31 error there at collection or setup, because the base has no telemetry/exporter.py, install_exporter or OtlpExportError.
  • uv run devops ci deps passes after the swap of opentelemetry-exporter-otlp-proto-grpc for opentelemetry-sdk; uv lock removes only the gRPC exporter.
  • Feasibility checks, the rejected alternatives (the SDK exporter interface as the seam, the SDK in-memory doubles, refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake) and the 2026-10-08 amendment are in openspec/changes/archive/2026-10-28-1319-otlp-exporter-seam/. The amendment's SDK-built spans and protobuf encoders are refactor(telemetry): Use OTel SDK encoders for spans, metrics, logs #2536.

Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).

…a shared fake

The tracer posted traces, metrics and logs through the private
`_send_payload` and `_send_payload_sync`, over a raw httpx2 client, and
probed the collector with a second raw client or a socket. A gRPC
protocol or endpoint posted OTLP/HTTP to the gRPC port, and every export
failed with only a count. Tests patched the private methods to read what
was exported.

- `telemetry/exporter.py` holds the `OtlpExporter` seam and the real
  `HttpOtlpExporter`, which posts through the egress-checked client at
  the private level and gives each failure one text. The probe posts an
  empty trace export request.
- `otlp_exporter` refuses a gRPC protocol or endpoint with an
  `OtlpProtocolError` that names the setting. The process tracer then
  keeps the command running with export off and warns once.
- The client takes its exporter; `install_exporter` and
  `remove_exporter` put one in place of the configured exporter.
- The gRPC exporter, the cached client and the socket probe are deleted,
  and `opentelemetry-sdk` replaces `opentelemetry-exporter-otlp-proto-grpc`
  in the direct dependencies.
- `FakeCollector` and the `otlp` fixture, with the contract suite in
  `tests/telemetry/`, replace the `captured` fixture and the patches of
  the migrated tests.
@dan-petty
dan-petty force-pushed the refactor/1319-otlp-exporter-seam branch from 2c13fca to dc68aba Compare October 28, 2026 21:20
@dan-petty
dan-petty merged commit 8da35e6 into main Oct 28, 2026
17 checks passed
@dan-petty
dan-petty deleted the refactor/1319-otlp-exporter-seam branch October 28, 2026 21:26
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.11.3](v0.11.2...v0.11.3)
(2026-10-28)


### Bug Fixes

* **roadmap:** refine wraps no link in the model's code, and wraps each
reference and link that GitHub makes from its text
([#2540](#2540))
([2d38f8d](2d38f8d)),
closes [#2525](#2525)


### Code Refactoring

* **docker:** DockerEngineService is the Docker engine seam, with an
in-memory engine fake and its contract suite
([#2534](#2534))
([1244cbf](1244cbf)),
closes [#1316](#1316)
* **security:** one keyring seam owns the keyring and the Secret
Service, with a shared fake and its contract suite
([#2532](#2532))
([866d2cb](866d2cb)),
closes [#1318](#1318)
* **telemetry:** OTLP export goes through one exporter seam, and tests
read exported spans and metrics from a shared fake
([#2541](#2541))
([8da35e6](8da35e6)),
closes [#1319](#1319)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
dan-petty added a commit that referenced this pull request Oct 28, 2026
…ort, 4318 (#2549)

The egress rule of the `devops` perimeter to the `otel` namespace
(`k8s/devops/networkpolicy.yaml`, rule 3) names the one port TCP 4318,
the collector's OTLP/HTTP port. It no longer allows TCP 4317.

devops-cli sends OTLP over HTTP only since #1319 (PR #2541): a gRPC
protocol or an endpoint on port 4317 is refused. No pod of the namespace
sends OTLP over gRPC: the devops config names port 4318, and Logfire
sends to its own HTTPS endpoint. So the open gRPC port was more than the
namespace needs.

- A manifest test, `test_devops_egress_to_otel_admits_only_otlp_http`,
fails when that rule names another port.
- The `otel` perimeter still admits 4317 from every namespace for other
clients, and the collector and Tempo keep their gRPC receivers.
- The `otlp-export` capability records the rule. `k8s/README.md` names
no port for this egress, so it stays correct.

Closes #2548

Change:
`openspec/changes/archive/2026-10-28-2548-devops-otlp-http-egress/`
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.

refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake

1 participant