Repository navigation
Description
Problem Description
The Service makes a second server span for each request, probes included. _service_trace_middleware (src/devops_cli/server/service.py) already skips CONST_SERVICE_PROBE_PATHS and names its spans HTTP <method> <path>. A second source of server spans makes GET /healthz, GET /readyz and GET /metrics (with http.route), and a duplicate POST /webhooks/github next to HTTP POST /webhooks/github at the same rate. This item is rank 11 of the cluster integration plan #4989.
Reproduction Steps
- In Tempo, search the roadmap-service spans for 10 min with TraceQL:
{ resource.service.name = "roadmap-service" && span.kind = server }. - Count the spans by name.
Expected vs Actual Behavior
Expected: one server span for each webhook request, and no span for /healthz, /readyz and /metrics.
Actual (Service 0.117.1, 2026-11-12): /healthz and /readyz 0.047 to 0.10 spans/s each, /metrics 0.007 to 0.017/s, and two server spans for each webhook. Probe spans are about 6 times the webhook spans. They fill the trace search and the Tempo storage (Tempo peaked at 76 % of its 2Gi limit). Loki shows a trace_id on each /readyz and /healthz access line.
Proposed Fix
Find the second source of server spans, remove the duplicate server span, and keep the probe paths out. Prove it with a fail-to-pass test. Do not add a collector filter: it hides the defect (AGENTS.md rule 11), and the gateway makes no probe spans.
Environment Diagnostics
roadmap-service 0.117.1 in the homelab cluster; traces to the cluster OpenTelemetry Collector and Tempo.
Logs, Traces, or Terminal Output
Tempo TraceQL rate, 05:30 to 05:40 UTC 2026-11-12, roadmap-service: /healthz 0.10/s, /readyz 0.10/s, /metrics 0.017/s, /webhooks/github 0.037/s.
Acceptance Criteria
- A test fails before the fix and passes after it: one request to the app makes one server span, and a probe request makes none.
- After the deploy, Tempo shows no
GET /healthz,GET /readyzorGET /metricsspans from roadmap-service.
Dependencies
None.
Source: #4989
Alternatives check of 2026-11-21: in-use.
The repository already uses this tool.
Tool: opentelemetry-instrumentation-fastapi (https://pypi.org/project/opentelemetry-instrumentation-fastapi), Apache-2.0, last activity 2026-10-29, maintained.
Reason: Searches and package facts show the OpenTelemetry FastAPI instrumentation, already used here, creates one server span per request with http.route and excludes probe URLs; it covers the span source but not deleting the hand-written middleware or the regression test.
Covers:
- One server span per request with http.route
- Probe paths dropped through excluded_urls, no collector filter
- Maintained auto-instrumentation instead of hand-written span code
Lacks:
- Does not remove the Service's own _service_trace_middleware
- No fail-to-pass regression test in the repository
- Server span names lose the
HTTP <method> <path>form
Proposed design
Problem statement
The Service creates two server spans for each HTTP request. The hand-written _service_trace_middleware in src/devops_cli/server/service.py creates one span and skips the probe paths. The OpenTelemetry FastAPI instrumentation creates a second span with http.route for the same request, including /healthz, /readyz and /metrics. The duplicate fills the trace search and Tempo storage. The fix keeps the maintained instrumentation, removes the hand-written middleware, sets excluded_urls to the probe paths, and adds a fail-to-pass test. After the deploy, Tempo must show no probe spans from the Service.
Acceptance criteria
Requirement: One server span per request
The Service SHALL create exactly one server span for each HTTP request to a path outside CONST_SERVICE_PROBE_PATHS.
Scenario: A webhook request creates one server span
- WHEN A test sends one POST request to /webhooks/github to the FastAPI app with an in-memory span exporter.
- THEN The exporter holds exactly one span whose kind is server.
Requirement: No server span for probe paths
The Service MUST create no server span for an HTTP request to a path in CONST_SERVICE_PROBE_PATHS.
Scenario: A health probe creates no server span
- WHEN A test sends one GET request to /healthz to the FastAPI app with an in-memory span exporter.
- THEN The exporter holds no span whose kind is server.
Requirement: One server-span source
The Service SHALL use the OpenTelemetry FastAPI instrumentation as its only source of server spans.
Scenario: The hand-written trace middleware is removed
- WHEN A test imports the module
devops_cli.server.service. - THEN The module does not define
_service_trace_middleware.
Requirement: Regression test covers the duplicate span
The change MUST add a regression test that detects the duplicate server span.
Scenario: The regression test fails on the unfixed code
- WHEN A test runs the new regression test against the code before the fix.
- THEN The regression test fails with two server spans for one request.
Existing Tool Considered
The repository already uses opentelemetry-instrumentation-fastapi (https://pypi.org/project/opentelemetry-instrumentation-fastapi), Apache-2.0, last activity 2026-10-29, maintained. It creates one server span per request with http.route and excludes probe URLs through excluded_urls, so it covers the probe half of the need without a collector filter. It cannot remove the duplicate span source: the Service must remove _service_trace_middleware and add the fail-to-pass test in its own code.
Key questions
- Which server-span source should the Service keep: the hand-written
_service_trace_middlewareor the OpenTelemetry FastAPI instrumentation?: Keep the OpenTelemetry FastAPI instrumentation and remove_service_trace_middleware. Setexcluded_urlsto the probe paths so the instrumentation creates no span for them. (best practice) [sources: src/devops_cli/server/service.py:1071, src/devops_cli/config/constants.py:1813]- Rejected: Keep the hand-written middleware and remove the instrumentor. It keeps code that the project builds and maintains itself, while the maintained instrumentation covers the need.
- Chosen: Keep the OpenTelemetry FastAPI instrumentation and remove the middleware. The maintained instrumentation creates the server span with http.route and excludes probe URLs before any span is created.
- How should the Service exclude the probe paths from spans?: Set the FastAPI instrumentation's
excluded_urlsto the comma-separated paths inCONST_SERVICE_PROBE_PATHS. (best practice) [sources: src/devops_cli/config/constants.py:1813]- Rejected: Add a collector filter. The issue forbids it because it hides the defect (AGENTS.md rule 11).
- Chosen: Set
excluded_urlson the FastAPI instrumentation. The instrumentation drops the probe request before any span is created, with no collector filter.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 12, 2026
Both target Service observability, but #4510 adds trace ids to log lines while this removes a duplicate server span.devops-cli-service commentedon Nov 15, 2026
Alternatives check: in-use
Reason: The searches point at the OpenTelemetry Python FastAPI/ASGI instrumentation as the likely second server-span source: its spans are named
GET /healthz/POST /webhooks/githubwithhttp.route, exactly the duplicates described. That instrumentation already covers the probe half of the need throughexcluded_urls/OTEL_PYTHON_FASTAPI_EXCLUDED_URLS, which drops/healthz,/readyzand/metricsbefore any span is created (no collector filter needed) and yields one server span per request. It cannot, however, remove the duplicate itself: the Service must delete one of its two span sources (the hand-written_service_trace_middlewareor the instrumentor) and add the fail-to-pass test in its own code.The repository already uses this tool.
Tool: opentelemetry-instrumentation-fastapi (https://pypi.org/project/opentelemetry-instrumentation-fastapi)
Covers:
Lacks:
Tools considered:
Searches run:
Sources:
Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 16, 2026
Status set to Ready at 181f85e (see proposed design in issue body).
fix(service): deduplicate server span and exclude probe paths (#5003)
fix(service): deduplicate server span and exclude probe paths (#5003)
devops-cli-service commentedon Nov 24, 2026
Released in v0.210.1: https://github.com/dan-petty/devops-cli/releases/tag/v0.210.1
devops-cli-service commentedon Nov 24, 2026
Live since 2026-11-24 18:31 UTC