Repository navigation
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/telemetryOpenTelemetry tracing spans, Prometheus metrics, and Jaegertype/refactorType refactor: a new structure, same behaviorvalue/highValue High: the delivery of the item matters much
Description
Problem
- Export is private.
OTelTelemetryClient[code: src/devops_cli/telemetry/tracer.py:690] posts traces (:1102) and metrics (:853) through the private_send_payload(:1232), which queues_send_payload_sync(:1216) on a background executor. The sync path posts OTLP/HTTP JSON with a client cached on the tracer by_get_http_client(:1201-1213). The collector probetest_connection(:1127) opens its own socket (:1143) or its own httpx2 client (:1180). - The gRPC exporter is dead code.
_get_grpc_exporter(:1104-1125) has no caller insrc; only tests/test_telemetry.py:440 calls it. Export is OTLP/HTTP JSON whateverprotocolsays (:703-711); the protocol only picks the probe (:1132). It is the only importer of theopentelemetry-exporter-otlp-proto-grpcdependency [code: pyproject.toml:40]. - Tests patch or call the privates. 12 test files patch or call
_send_payloador_send_payload_sync[measured: grep at 5c45b1e].forbid_requestspatches the private_resolve_telemetry_settings[code: tests/cluster_secret_fakes.py:231]. - Every test exports. The per-test config turns telemetry on at a loopback collector [code: tests/conftest.py:465, :471], so each span queues a POST that the network guard refuses. test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 turns export off by default, and a test that checks telemetry opts in with this item's fake (Q28).
Acceptance criteria
Seam
- An exporter Protocol names what the tracer needs of a collector: export one signal's payload (traces or metrics) and probe the collector. The real implementation is today's OTLP/HTTP JSON export and probe, moved out of the tracer. The tracer takes its exporter from one place, which
get_tracer()(:1303) uses. - The background executor, the dry-run suppression (:1239) and the success and failure counters stay in the tracer and behave as today.
-
_get_grpc_exporterand_grpc_exporter(:719, :1104-1125, :1270-1275) are deleted, as no public behaviour reaches them (Q22), andopentelemetry-exporter-otlp-proto-grpcleaves the direct dependencies (pyproject.toml:40).
Fake and fixture
-
tests/support/fakes/otlp.pyrecords each export (signal and payload) and offers the exported span names and attributes and metric names and points as plain values. It can answer an export with a failure status or a refused connection, and its probe answer is configurable. - A fixture opts the test into telemetry with the fake as exporter, restores the real exporter at teardown and returns it, registered once from the root conftest. Reading the fake first waits for queued exports through the tracer's public
flush()(:1249); no test sleeps.
Contract suite
- One suite in
tests/telemetry/runs against the fake and the real exporter, the real side posting to an OTLP/HTTP receiver on a loopback port the test owns. Cases: the receiver gets the payload sent, on the signal's path; a 2xx counts a success; a 4xx, a 5xx and a refused connection each count a failure with the samelast_export_erroron both sides; the probe reports a reachable and an unreachable collector.
Migration
- tests/test_telemetry_collector_export.py and the export tests in tests/test_telemetry.py (paths before test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313's move) use the fake or the contract suite, and patch or call no
_send_payload,_send_payload_sync,_get_http_clientor_grpc_exporter. - The other 10 files that reach
_send_payload(among them tests/test_telemetry_cmd.py, test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327's, and tests/test_otel_command_coverage.py, test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334's) andforbid_requestsare left to the package items whose file lists name them. Until then a test that opted in under test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 keeps its current sink. - Tests run offline; each new test runs under 1 s.
- If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings drop by the sites this PR removes (the
_send_payload_syncpatches in tests/test_telemetry_collector_export.py among them). -
uv run devops cipasses.
Key questions
- Is OTLP export an edge apart from HTTP? Decided 2026-10-07: yes, it is its own faked edge (Q23). Tests check spans and metrics, not HTTP requests.
- Is telemetry on in tests? Decided 2026-10-07: off by default; a test opts in with the OTLP fake (Q28). test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 turns it off.
- Where does the exporter's HTTP client come from? (proposed) From refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam once both have landed. Until then the exporter keeps its own cached client; telemetry/tracer.py is one of the inline builders test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334 routes.
- What about Logfire? (proposed) Out of scope: the Logfire bridge (telemetry/logfire.py) and fix(ci): review workflow tests start the logfire SDK's credential check, which the network guard blocks #965's credential check are separate.
- Fixture name? (proposed)
otlp.
Strategic alignment
- Depends on: test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312. Blocks: test(github): github/ is tested through its public interface over the gh process and session fakes, with no internal patches or private imports #1321, test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326, test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327, test(ai): Wire rag once in ai/rag, test with edge fakes #1329, test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331, test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332, test(cli): Use edge fakes and real git; drop test rebind hooks #1333, test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334, test(infra): infrastructure tests run on edge fakes #1335. Related: test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 (export off by default), refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 (HTTP seam), fix(ci): review workflow tests start the logfire SDK's credential check, which the network guard blocks #965 (Logfire credential check in review tests).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase D).
Proposed design
Problem statement
The telemetry exporter in OTelTelemetryClient posts traces and metrics through private methods, and 12 test files patch those privates. The gRPC exporter is dead code with no caller in src. Tests cannot read exported spans and metrics without patching internals. This item creates one exporter seam based on the SDK's SpanExporter and MetricExporter interface, deletes the gRPC path, and gives tests a shared fake and a contract suite so they check exported values, not HTTP requests.
Acceptance criteria
- Criterion 1: The tracer takes its exporter from one place, and get_tracer() uses it.
Verification: grep for get_tracer in src/devops_cli/telemetry/tracer.py shows it passes the exporter to the tracer constructor. - Criterion 2: The real exporter implements the SDK's SpanExporter and MetricExporter, serialises with the official encoders, and POSTs application/x-protobuf.
Verification: The exporter module imports encode_spans and encode_metrics from opentelemetry.exporter.otlp.proto.common and sets Content-Type to application/x-protobuf. - Criterion 3: The background executor, dry-run suppression, and success and failure counters stay in the tracer and behave as today.
Verification: tests/test_telemetry_collector_export.py tests for dry-run, shutdown drain, and failure counting pass without change to their assertions. - Criterion 4: _get_grpc_exporter, _grpc_exporter, and the opentelemetry-exporter-otlp-proto-grpc dependency are deleted.
Verification: grep -r '_get_grpc_exporter|_grpc_exporter' src/ returns no results; pyproject.toml has no opentelemetry-exporter-otlp-proto-grpc line. - Criterion 5: Setting protocol to grpc raises an error that names the setting.
Verification: A test sets OTEL_EXPORTER_OTLP_PROTOCOL=grpc and asserts the raised error message contains the setting name. - Criterion 6: A fake records each export (signal and payload) and offers span names, attributes, metric names, and points as plain values.
Verification: A test exports a span and a metric through the fake, then reads the recorded span name and metric name as plain strings. - Criterion 7: The fake can answer an export with a failure status or a refused connection, and its probe answer is configurable.
Verification: A test sets the fake to refuse, exports, and asserts the failure counter increments; a test sets the probe answer and asserts test_connection returns it. - Criterion 8: A fixture named otlp opts the test into telemetry with the fake as exporter, restores the real exporter at teardown, and is registered once from the root conftest.
Verification: pytest --fixtures | grep otlp shows the fixture; a test that requests otlp sees the fake installed and a later test sees the real exporter restored. - Criterion 9: Reading the fake first waits for queued exports through the tracer's public flush(); no test sleeps.
Verification: grep -r 'time.sleep|asyncio.sleep' tests/telemetry/ returns no results in the new tests. - Criterion 10: One contract suite in tests/telemetry/ runs against the fake and the real exporter on a loopback port the test owns.
Verification: pytest tests/telemetry/test_contract.py passes; the real side binds a loopback port and the test asserts the receiver gets the payload on the signal's path. - Criterion 11: The contract suite covers: 2xx counts a success; 4xx, 5xx, and refused connection each count a failure with the same last_export_error on both sides; the probe reports reachable and unreachable.
Verification: pytest tests/telemetry/test_contract.py -v shows all cases pass on both the fake and the real exporter. - Criterion 12: tests/test_telemetry_collector_export.py and the export tests in tests/test_telemetry.py use the fake or the contract suite and patch no _send_payload, _send_payload_sync, _get_http_client, or _grpc_exporter.
Verification: grep -n '_send_payload|_send_payload_sync|_get_http_client|_grpc_exporter' tests/test_telemetry_collector_export.py tests/test_telemetry.py returns no results. - Criterion 13: Tests run offline and each new test runs under 1 s.
Verification: pytest tests/telemetry/ --durations=10 shows no test exceeds 1 s; no external network calls are made. - Criterion 14: uv run devops ci passes.
Verification: The CI check reports a passing status.
Key questions
- Is OTLP export an edge apart from HTTP?: Yes. It is its own faked edge (Q23). Tests check spans and metrics, not HTTP requests. (proposed)
- Is telemetry on in tests?: Off by default. A test opts in with the OTLP fake (Q28). test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 turns it off. (proposed)
- Where does the exporter's HTTP client come from?: From refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam once both have landed. Until then the exporter keeps its own cached client; telemetry/tracer.py is one of the inline builders test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334 routes. (proposed)
- What about Logfire?: Out of scope. The Logfire bridge (telemetry/logfire.py) and fix(ci): review workflow tests start the logfire SDK's credential check, which the network guard blocks #965's credential check are separate. (proposed)
- Fixture name?: otlp. (proposed)
- What interface does the exporter seam use?: The SDK's SpanExporter and MetricExporter, per the 2026-10-08 amendment. The real implementation serialises with the official encoders and POSTs application/x-protobuf through the egress factory. (proposed)
- What fake do tests use?: Preferred: refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake, with tests decoding ExportTraceServiceRequest and ExportMetricsServiceRequest. If an exporter-level fake is still wanted, use the SDK's InMemorySpanExporter and InMemoryMetricReader. (proposed)
- What happens when protocol is set to grpc?: It fails with an error naming the setting, instead of silently posting HTTP/JSON to a gRPC port. (proposed)
- Does the gRPC exporter have a caller in src?: No. Only tests/test_telemetry.py:462 calls _get_grpc_exporter. No code in src/ calls it. [sources: src/devops_cli/telemetry/tracer.py:1288, tests/test_telemetry.py:462]
- Does the per-test config turn telemetry on at a loopback collector?: Yes. The isolate_devops_cli_config fixture writes telemetry.enabled: false and points the endpoint at the unserved_side_channel_port, a refusing loopback port. [sources: tests/conftest.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/telemetryOpenTelemetry tracing spans, Prometheus metrics, and Jaegertype/refactorType refactor: a new structure, same behaviorvalue/highValue High: the delivery of the item matters much
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 8, 2026
Amendment proposed by the 2026-10-08 client-library audit: the seam is the OpenTelemetry SDK's exporter interface, not a Protocol around today's hand-built OTLP/HTTP JSON.
MeterProvider.refactor(telemetry): spans are built and exported by the OpenTelemetry SDK, ...._to_otlp_any_value, the per-span POST and the hand-built resource (telemetry/tracer.py:111-129,:732-772,:1101-1102at 05e9388) as "the real implementation" entrenches what those items delete.SpanExporterandMetricExporter.opentelemetry.exporter.otlp.proto.common.trace_encoder.encode_spansandmetrics_encoder.encode_metrics).application/x-protobufthrough the egress factory. The SDK's stock OTLP/HTTP exporters take only arequests.Session, so they would bypass the factory's connect-time check and refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake.ExportTraceServiceRequestandExportMetricsServiceRequest.InMemorySpanExporterandInMemoryMetricReaderrather than a newtests/support/fakes/otlp.py._get_grpc_exporterand droppingopentelemetry-exporter-otlp-proto-grpcstill hold.grpcas protocol should then fail with an error naming the setting, instead of silently posting HTTP/JSON to a gRPC port (:703-711,:1216).test_connection,:1127-1191, raw socket:1143and client:1180) becomes a request through the factory client.Folded here instead of a new issue: the agent filing quota (#1153) is spent for this cycle, and this refactor shares this item's change surface. It is recorded here in full so it is not lost.
refactor(telemetry): spans are built and exported by the OpenTelemetry SDK, and the hand-built OTLP encoder, second context store and traceparent formatters are removed
Problem
Lines cited at 05e9388 (
release/v0.2.29)._to_otlp_any_value(telemetry/tracer.py:111-129) encodes AnyValue by hand.:732-772) that names itselftelemetry.sdk.name = "devops-cli-otel"._build_traces_payload([span_data]),:1101-1102), from a two-worker pool (:1196), over a rawhttpx2.Client(:1213). The collector is therefore dialled outside the egress factory.protocolresolves togrpcforOTEL_EXPORTER_OTLP_PROTOCOL=grpcor a:4317endpoint (:703-711)._send_payload_sync(:1216) still POSTs HTTP/JSON to{endpoint}/v1/traces._get_grpc_exporter(:1104-1125) has no caller. The failures are only counted.srcreadsOTEL_RESOURCE_ATTRIBUTES,OTEL_EXPORTER_OTLP_HEADERS,OTEL_TRACES_SAMPLERorOTEL_SDK_DISABLED.telemetry/logfire.py:206-210).LogfireOTelBridgeProcessor(:39-84) converts each SDK span back into the hand-built dict (record_completed_span,:84).tracer.py:686-687). A pydantic-ai span started insidetrace_spanfinds its parent only where code goes throughget_current_span_context(:1408-1430).traceparentis formatted in four places:telemetry/propagation.py:82-95,server/app.py:98(always sampled,01),ai/run/__init__.py:67and the tracer. Parsing is hand-written as well (propagation.py:105-136).opentelemetry-sdkandopentelemetry-exporter-otlp-proto-common1.44.0 arrive through logfire and through the direct dependencyopentelemetry-exporter-otlp-proto-grpc(pyproject.toml:40).MeterProvider. refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319, as written, keeps today's OTLP/HTTP JSON export as the real implementation of its seam.Proposed remedy
TracerProvider, shared with Logfire, with aBatchSpanProcessor. The SDK builds theResource(OTEL_SERVICE_NAME,OTEL_RESOURCE_ATTRIBUTES).SpanExporterserialises with the official encoder (opentelemetry.exporter.otlp.proto.common.trace_encoder.encode_spans). It POSTsapplication/x-protobufthrough the egress factory (devops_cli.http.client) at the collector's level.requests.Session. It would bypass fix(security): every HTTP client dials only addresses its egress level allows, checked at the connect and on every redirect #898's connect-time check and refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake.opentelemetry.trace.propagation.tracecontext.TraceContextTextMapPropagatorcarries context over HTTP headers. Child processes get the same propagator over theirTRACEPARENT/TRACESTATEenvironment, through a getter and setter for the upper-case keys.trace_span,tracedandSpanHandlekeep their public signatures as thin wrappers over the SDK span.grpcas protocol is refused with an error naming the setting.opentelemetry-exporter-otlp-proto-grpcleaves the direct dependencies;opentelemetry-sdkandopentelemetry-exporter-otlp-proto-commonjoin them.Key questions
opentelemetry.proto.collector.trace.v1.trace_service_pb2.ExportTraceServiceRequest.SpanExporteras its seam instead of defining a new Protocol.LoggerProviderwithLoggingHandler), not on a third hand-built signal.Acceptance criteria
rg -n 'stringValue|resourceSpans|scopeSpans|kvlistValue' src/devops_cliprints nothing.LogfireOTelBridgeProcessor,_current_trace_id_ctx,_current_span_id_ctx,_get_grpc_exporter, and the hand-written traceparent parsing and formatting. One function renders a traceparent.trace_spanhas the CLI span as its parent: the same trace id, and the CLI span's id as parent span id.ExportTraceServiceRequestand carries the resource attributes fromOTEL_RESOURCE_ATTRIBUTES.OTEL_EXPORTER_OTLP_PROTOCOL=grpcfails with an error naming the setting.--dry-runpreviews for delegated commands #412).changelog.d/<n>.mdrecords the change;CHANGELOG.mdanddocs/ROADMAP.mdare not edited.uv run devops cipasses.Related: #792 (metrics through the SDK), #1319 (exporter seam), #1314 (HTTP seam), #1334, #813, #1418, #702, #1120.
Found by the 2026-10-08 client-library audit.
dan-petty commentedon Oct 8, 2026
Linked: #792, #813 and #1418 replace or fix other parts of the hand-built OTLP in
telemetry/tracer.py, and #1381 lists this item's two clients (:1180,:1213); whichever lands first moves them. Found by the 2026-10-08 backlog review.2 remaining items
dan-petty commentedon Oct 26, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
This item is medium priority as it improves code structure and testability but does not address an immediate bug or security issue.High value because it improves the reliability and testability of telemetry exports by centralizing the export mechanism.High effort due to the extensive refactoring required across multiple modules and the need to update tests accordingly.Both items are about telemetry tests and fakes, but the candidate focuses on refactoring OTLP export through a single exporter seam while item #1334 is about migrating test files to use edge fakes.dan-petty commentedon Oct 28, 2026
Status set to Ready at 69636b6 (see proposed design in issue body).
dan-petty commentedon Oct 28, 2026
PR #2541 builds this item. One decision differs from the refine block's criterion 2:
OtlpExporterintelemetry/exporter.py: export one signal's encoded request, and probe. It is not the SDK'sSpanExporterandMetricExporter. ASpanExportertakes SDKReadableSpanobjects, and the tracer's spans stay hand-built dicts until the SDK builds them. That is the refactor the 2026-10-08 amendment recorded here because the filing quota was spent then. It is now refactor(telemetry): Use OTel SDK encoders for spans, metrics, logs #2536, which encodes with the official protobuf encoders and calls this seam, so the egress-checked client, the OTLP fake and its contract suite stay._get_grpc_exporterandopentelemetry-exporter-otlp-proto-grpcare gone, and a gRPC protocol or endpoint fails with an error that names the setting.FakeCollector(tests/support/fakes/otlp.py, fixtureotlp), not the SDK's in-memory doubles: the spans and logs are not SDK objects yet, and the in-memory doubles give no failure or probe answer for the contract suite to compare.chore(main): release 0.11.3 (#2539)
fix(k8s): the devops perimeter opens only the collector's OTLP/HTTP port
fix(k8s): the devops perimeter opens only the collector's OTLP/HTTP p…
feat(telemetry): send pydantic-ai spans through the exporter seam (#4538