Repository navigation
Description
Problem or Motivation
The 2026-10-08 client-library audit added this work to #1319 as a comment only because the agent filing quota was spent then. #1319 delivers the exporter seam: OtlpExporter and HttpOtlpExporter in src/devops_cli/telemetry/exporter.py, the OTLP fake tests/support/fakes/otlp.py with its contract suite, the move of the export and probe clients onto the egress-checked factory, and the refusal of gRPC. The export requests are still built by hand:
telemetry/tracer.pyencodes OTLP/JSON by hand:_to_otlp_any_value, the hand-built resource attribute list (telemetry.sdk.name = devops-cli-otel),_build_traces_payload,_build_logs_payloadand_encode_sdk_metrics_datawith its helpers.- Each span is one export request, so the N spans of one command send N requests.
LogfireOTelBridgeProcessor(telemetry/logfire.py) turns each SDK span back into the hand-built dict, and CLI spans keep their ids in the tracer's own context variables.traceparentis formatted in several places (telemetry/propagation.py,server/app.py,ai/run/__init__.pyand the tracer), and parsed by hand.- Nothing in
srcreadsOTEL_RESOURCE_ATTRIBUTES,OTEL_EXPORTER_OTLP_HEADERS,OTEL_TRACES_SAMPLERorOTEL_SDK_DISABLED.
Proposed Solution & Architectural Design
- One SDK
TracerProvider, shared with Logfire, with aBatchSpanProcessor. The SDK builds theResourcefromOTEL_SERVICE_NAMEandOTEL_RESOURCE_ATTRIBUTES. - An SDK
SpanExporter,MetricExporterandLogExporterencode with the official encoders (opentelemetry.exporter.otlp.proto.common:encode_spans,encode_metrics,encode_logs) and hand theapplication/x-protobufbody to theOtlpExporterseam of refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319, so the egress-checked client and the contract suite stay. - The OTLP fake decodes protobuf with the
opentelemetry.protorequest classes and keeps its plain-value views. TraceContextTextMapPropagatorcarries context over HTTP headers and, through a getter and setter for the upper-case keys, overTRACEPARENTandTRACESTATEin a child's environment.trace_span,tracedandSpanHandlekeep their public signatures as thin wrappers over the SDK span.- Deleted: the hand-built encoders,
LogfireOTelBridgeProcessor, the tracer's context variables and the hand-written traceparent parsing and formatting. - When the change is too large for one pull request, it becomes sub-issues, for example spans and propagation first, then metrics and logs.
Target Subsystem
Telemetry: src/devops_cli/telemetry/ (tracer, logfire bridge, propagation, logging bridge), server/app.py, ai/run/__init__.py, and the OTLP fake.
Existing Tool Considered
The OpenTelemetry SDK (opentelemetry-sdk, already a direct dependency) and its official OTLP encoders (opentelemetry-exporter-otlp-proto-common). The SDK's own OTLP/HTTP exporters take only a requests.Session, which would bypass the egress-checked client and the OTLP fake, so the SDK exporters wrap the #1319 seam instead. Nothing is built beyond thin exporter classes; the change deletes the hand-built encoding.
Acceptance criteria
rg -n 'stringValue|resourceSpans|scopeSpans|kvlistValue' src/devops_cliprints nothing.- A pydantic-ai span started inside
trace_spanhas the CLI span as its parent: the same trace id, and the CLI span's id as its parent span id. - The N spans one command ends produce one export request at the OTLP fake. Its body decodes as
ExportTraceServiceRequestand carries the resource attributes ofOTEL_RESOURCE_ATTRIBUTES. - One function renders a traceparent.
- A dry run makes no request (feat(cli): reachable
--dry-runpreviews for delegated commands #412). - The contract suite of refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 passes with protobuf bodies on both sides.
- Tests run offline; each new test runs in under 1 s.
uv run devops cipasses.
Related
#1319 (the exporter seam it builds on), #1307, #1334, #1314.
Source: #1319
Proposed design
Problem statement
The telemetry subsystem hand-builds OTLP/JSON export requests and sends one HTTP request per span. It hand-parses and formats traceparent in four places. It ignores the OTEL_RESOURCE_ATTRIBUTES, OTEL_EXPORTER_OTLP_HEADERS, OTEL_TRACES_SAMPLER, and OTEL_SDK_DISABLED environment variables. This refactor replaces the hand-built encoding with the OpenTelemetry SDK official protobuf encoders and BatchSpanProcessor. It keeps the egress-checked exporter seam from #1319.
Acceptance criteria
Requirement: No hand-built OTLP JSON identifiers
The source tree SHALL contain no hand-built OTLP JSON field identifiers.
Scenario: grep for OTLP JSON identifiers
- WHEN rg -n 'stringValue|resourceSpans|scopeSpans|kvlistValue' src/devops_cli is run
- THEN the command prints nothing
Requirement: Pydantic-ai span parent-child
A pydantic-ai span started inside trace_span SHALL have the CLI span as its parent.
Scenario: span parent-child relationship
- WHEN a pydantic-ai span is started inside a trace_span context
- THEN the pydantic-ai span has the same trace id as the CLI span and the CLI span id as its parent span id
Requirement: Batched export
The N spans one command ends SHALL produce one export request at the OTLP fake.
Scenario: multiple spans one request
- WHEN a command ends N spans
- THEN the OTLP fake receives one export request whose body decodes as ExportTraceServiceRequest and carries the resource attributes of OTEL_RESOURCE_ATTRIBUTES
Requirement: Single traceparent renderer
One function SHALL render a traceparent.
Scenario: traceparent rendering
- WHEN code needs to format a traceparent header
- THEN it calls the single rendering function
Requirement: Dry run makes no request
A dry run SHALL make no export request.
Scenario: dry run no export
- WHEN a command runs in dry-run mode
- THEN no export request is sent to the collector
Requirement: Contract suite with protobuf
The contract suite of #1319 SHALL pass with protobuf bodies on both sides.
Scenario: contract suite protobuf
- WHEN the contract suite runs the same cases over the OTLP fake and over HttpOtlpExporter
- THEN all cases pass with application/x-protobuf content type
Requirement: Offline tests under one second
Each new test SHALL run offline in under one second.
Scenario: test duration
- WHEN each new test runs
- THEN it completes in under one second without network access
Requirement: CI passes
uv run devops ci SHALL pass.
Scenario: CI gate
- WHEN uv run devops ci is run
- THEN all checks pass
Existing Tool Considered
opentelemetry-sdk (already a direct dependency) and opentelemetry-exporter-otlp-proto-common (the official OTLP protobuf encoders: encode_spans, encode_metrics, encode_logs). The SDK's own OTLP/HTTP exporters take only a requests.Session, which bypasses the egress-checked client of #1319. The project builds three thin exporter classes (SpanExporter, MetricExporter, LogExporter) that call the official encoders and hand the application/x-protobuf body to the OtlpExporter protocol, and updates the OTLP fake to decode protobuf with opentelemetry.proto request classes. The written cost is the three thin exporter classes and the updated OTLP fake decoder; the change deletes the hand-built encoders, LogfireOTelBridgeProcessor, the tracer context variables, and the hand-written traceparent code.
Key questions
- Which library provides the OTLP protobuf encoders?: opentelemetry-exporter-otlp-proto-common provides encode_spans, encode_metrics, and encode_logs. The project calls these functions and hands the resulting application/x-protobuf body to the OtlpExporter protocol of refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319. (best practice) [sources: src/devops_cli/telemetry/exporter.py, openspec/changes/archive/2026-10-28-1319-otlp-exporter-seam/proposal.md]
- Chosen: Use opentelemetry-exporter-otlp-proto-common encoders. The official encoders produce the correct protobuf wire format. The project already depends on opentelemetry-sdk.
- Rejected: Keep hand-building OTLP/JSON. The goal of this issue is to delete the hand-built encoders. Keeping them defeats the purpose.
- Rejected: Use the SDK built-in OTLP/HTTP exporters directly. They take only a requests.Session, which bypasses the egress-checked client of refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 and the OTLP fake.
- How do the SDK exporters integrate with the refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 OtlpExporter seam?: Three thin classes (SpanExporter, MetricExporter, LogExporter) implement the SDK exporter interfaces. Each calls the official encoder and hands the protobuf body to the OtlpExporter.export method with content_type application/x-protobuf. The egress-checked client and the contract suite stay unchanged. (best practice) [sources: src/devops_cli/telemetry/exporter.py, tests/support/fakes/otlp.py]
- Chosen: Thin exporter classes wrapping the OtlpExporter protocol. Keeps the egress-checked client, the contract suite, and the OTLP fake. Adds only three small classes.
- Rejected: Replace the OtlpExporter seam with the SDK exporters. Loses the egress-checked client and the contract suite. The SDK exporters use requests.Session directly.
- Which propagator handles traceparent over HTTP headers and child environment?: TraceContextTextMapPropagator from opentelemetry-api carries context over HTTP headers. A getter and setter for the upper-case keys TRACEPARENT and TRACESTATE carry it in a child process environment. This replaces the hand-written parsing and formatting in telemetry/propagation.py, server/app.py, ai/run/init.py, and the tracer. (best practice) [sources: src/devops_cli/telemetry/propagation.py]
- Chosen: TraceContextTextMapPropagator with env getter and setter. The standard W3C propagator. One function renders a traceparent. The env getter and setter cover child processes.
- Rejected: Keep hand-written traceparent parsing and formatting. The goal is to delete the hand-written code. It is duplicated in four places.
- How does the OTLP fake decode protobuf export requests?: The fake decodes the application/x-protobuf body with the opentelemetry.proto request classes (ExportTraceServiceRequest, ExportMetricsServiceRequest, ExportLogsServiceRequest). It keeps its plain-value views (ExportedSpan, metric points, log records) so existing tests read the same shape. (best practice) [sources: tests/support/fakes/otlp.py]
- Chosen: Decode with opentelemetry.proto request classes. The official protobuf classes parse the wire format correctly. The fake keeps its plain-value views for test readability.
- Rejected: Keep decoding JSON. The body will now be protobuf. JSON decoding will fail.
- Does the change fit in one pull request?: No. The change touches the tracer, the logfire bridge, propagation, the logging bridge, metrics, server/app.py, ai/run/init.py, the OTLP fake, and the contract suite. The body suggests splitting into spans and propagation first, then metrics and logs. (best practice) [sources: src/devops_cli/telemetry/tracer.py, src/devops_cli/telemetry/logfire.py:40, src/devops_cli/telemetry/propagation.py, tests/support/fakes/otlp.py]
- Chosen: Split into two pull requests: spans and propagation, then metrics and logs. Each PR is smaller and reviewable. The spans and propagation PR delivers the BatchSpanProcessor, the propagator, and the traceparent cleanup. The metrics and logs PR delivers the MetricExporter and LogExporter.
- Rejected: One large pull request. Too many files and too much new code for one review. The body itself suggests splitting.
- How does the SDK build the Resource from environment variables?: The SDK TracerProvider reads OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES to build the Resource. This replaces the hand-built resource attribute list (telemetry.sdk.name = devops-cli-otel) in the tracer. (best practice) [sources: src/devops_cli/telemetry/tracer.py]
- Chosen: Let the SDK read OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES. The standard OpenTelemetry environment variables. The SDK already parses them. This deletes the hand-built resource attribute list.
- Rejected: Keep the hand-built resource attribute list. Does not support OTEL_RESOURCE_ATTRIBUTES. The goal is to support the standard variables.
- What happens to the public API of trace_span, traced, and SpanHandle?: They keep their public signatures as thin wrappers over the SDK span. Callers see no change. The internal implementation switches from the hand-built tracer to the SDK TracerProvider. (best practice) [sources: src/devops_cli/telemetry/tracer.py, src/devops_cli/telemetry/init.py]
- Chosen: Keep public signatures as thin wrappers over SDK spans. Callers see no change. The wrappers are small and testable.
- Rejected: Expose SDK spans directly to callers. Breaks every caller of trace_span, traced, and SpanHandle. Too large a change for this issue.
- What happens to LogfireOTelBridgeProcessor?: It is deleted. The SDK TracerProvider is shared with Logfire, so Logfire spans enter the same BatchSpanProcessor and export through the same seam. The bridge that turned each SDK span back into a hand-built dict is no longer needed. (best practice) [sources: src/devops_cli/telemetry/logfire.py:40, src/devops_cli/telemetry/init.py:101]
- Chosen: Delete LogfireOTelBridgeProcessor and share the TracerProvider with Logfire. The bridge exists only because the tracer and Logfire used separate span pipelines. A shared TracerProvider removes the need.
- Rejected: Keep the bridge. The goal is to delete hand-built code. The bridge is hand-built and becomes redundant with a shared TracerProvider.
- Is opentelemetry-sdk already a direct dependency of this project?: Yes. The body states it is already a direct dependency. The knowledge base document for OpenTelemetry confirms the SDK is in use. [sources: src/devops_cli/ai/knowledge_base/devops_cli/libraries/opentelemetry.md:51]
- Does the refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 exporter seam exist and is it delivered?: Yes. The OtlpExporter protocol, HttpOtlpExporter, and the OTLP fake are in the codebase. The refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 change is archived in openspec/changes/archive/2026-10-28-1319-otlp-exporter-seam/. [sources: src/devops_cli/telemetry/exporter.py, tests/support/fakes/otlp.py, openspec/changes/archive/2026-10-28-1319-otlp-exporter-seam/proposal.md]
Fit
Needs splitting into 2 items:
- Spans and propagation: SDK TracerProvider with BatchSpanProcessor, TraceContextTextMapPropagator with env getter and setter, delete LogfireOTelBridgeProcessor, update server/app.py and ai/run/init.py, OTLP fake decodes protobuf traces, contract suite passes with protobuf traces
- Metrics and logs: SDK MetricExporter and LogExporter with official encoders, OTLP fake decodes protobuf metrics and logs, contract suite passes with protobuf metrics and logs
Suspected block
None.
Dependencies
Alternatives check of 2026-11-04: not-applicable.
Class: refactor, no search.
Tool: none found.
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The title is prefixed refactor and the body replaces hand-built encoders with SDK-provided ones without changing the public API.It improves performance and maintainability but the current hand-built code functions, so it is not urgent.Users gain batched exports, OTEL_* environment variable support, and reduced request count per command.The change touches tracer, logfire bridge, propagation, server app, ai/run, and the OTLP fake, and the body notes it may split into sub-issues.Both work in the telemetry subsystem on traceparent propagation and the OpenTelemetry SDK, but #319 adds initial propagation and metric SDK while the candidate replaces the encoding layer with official SDK protobuf encoders and BatchSpanProrefactor(telemetry): OTLP export goes through one exporter seam, and …
devops-cli-service commentedon Oct 29, 2026
The proposal at 0f7bc26 needs splitting into 2 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.
devops-cli-service commentedon Nov 4, 2026
Alternatives check: not-applicable
Class: refactor. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-04. A person decides what this means for the item. The check changes no label and closes no issue.
[-]refactor(telemetry): spans, metrics and logs are built and encoded by the OpenTelemetry SDK and sent as OTLP protobuf through the exporter seam[/-][+]refactor(telemetry): Use OTel SDK encoders for spans, metrics, logs[/+]dan-petty commentedon Nov 6, 2026
The job shortened the title of this item. The summary had 122 characters, and the limit is 60. The type and the scope stay.
refactor(telemetry): spans, metrics and logs are built and encoded by the OpenTelemetry SDK and sent as OTLP protobuf through the exporter seamrefactor(telemetry): Use OTel SDK encoders for spans, metrics, logsdan-petty commentedon Nov 21, 2026
A measure for the point "Each span is one export request", on main (752c6ed).
Tracerends each span with_send_payload("/v1/traces", self._build_traces_payload([span_data]))(src/devops_cli/telemetry/tracer.pyline 1415). Each program thatcore/process.pystarts opens a spansubprocess.<bin>(line 905). The project review of #4692 starts oneopenspec showprogram for each archived change: a 7-daydevops roadmap review runmakes 329 OpenSpec reads. So, with tracing on, one review sends about 350 trace requests. TheBatchSpanProcessorof the design of this item removes that cost.