Skip to content

feat: add OTLP metrics ingest endpoint (POST /api/public/otel/v1/metrics) - #2

Merged
EeroEternal merged 3 commits into
mainfrom
devin/1783339838-xtrace-otlp-metrics
Jul 6, 2026
Merged

feat: add OTLP metrics ingest endpoint (POST /api/public/otel/v1/metrics)#2
EeroEternal merged 3 commits into
mainfrom
devin/1783339838-xtrace-otlp-metrics

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Roadmap item X0: add an OTLP metrics ingest endpoint so upstream services can push OTel metrics into xtrace over the same OTLP path they already use for traces (previously xtrace only accepted OTLP traces). New route POST /api/public/otel/v1/metrics, symmetric to post_otel_traces, landing data into the existing metrics point table — no schema change / no migration.

Transport mirrors the traces handler exactly (reuses ungzip_if_needed, content-type branch, JSON via serde + application/x-protobuf via prost ExportMetricsServiceRequest). Auth is symmetric too — the new path joins the Langfuse/open-compat allowance set alongside the traces endpoint.

OTLP → point-model mapping (walk resource_metrics → scope_metrics → metrics), reusing the existing metrics_tx → metrics_worker → write_metrics_batches write path (not the trace ingest_tx):

Gauge / Sum:  each NumberDataPoint            -> one metrics row
                name  = metric.name
                value = as_double | (as_int as f64)
                ts    = time_unix_nano -> DateTime<Utc>
                labels = merge(Resource, Scope, DataPoint attrs)
Histogram:    -> {name}_count (= count), {name}_sum (= sum)   # derived points
ExponentialHistogram / Summary / no-data:  log-and-skip (does not fail the request)

labels merge Resource + Scope (otel.scope.name/version) + DataPoint attributes; GenAI semantic-convention keys (gen_ai.*, service.name) are carried verbatim as label keys — semantics via naming convention only, no business-specific columns (per AGENTS.md substrate boundary).

Note on histograms: xtrace computes true quantiles over raw sample points (percentile_cont), so the {name}_count/{name}_sum derived rows are an OTLP-input compatibility shim, not a source for p99 — latency-type metrics should still be pushed as one raw point per request (X1 semantics note). A code comment records this.

Also folds in a few preexisting clippy fixes required to get the cargo clippy -- -D warnings gate green (a newer stable clippy, rust-1.92.0, promoted collapsible_if / redundant_closure / type_complexity to errors in untouched files — src/http/metrics.rs, src/http/traces.rs, src/ingest/batch.rs); these are mechanical and behavior-preserving.

Test

  • New integration tests (tests/integration_test.rs, mock + Postgres-backed via oneshot): JSON OTLP metrics round-trip (Gauge + Sum) read back through GET /api/public/metrics/query, protobuf round-trip, Histogram producing {name}_count/{name}_sum, and an auth-symmetry check. Plus a unit test locking the JSON mapping.
  • Full CI gate run locally, all green: cargo fmt --all --check, cargo clippy --all-targets --all-features -- -D warnings, and cargo test --all against Postgres 16 (DATABASE_URL=postgres://xtrace:xtrace@localhost:5432/xtrace).
  • docs/project_status.md snapshot refreshed per AGENTS.md.

Link to Devin session: https://app.devin.ai/sessions/0314a364b623468489f859563573e8e7
Requested by: @EeroEternal

…ics)

Co-Authored-By: pi li <songmqq@proton.me>
@EeroEternal EeroEternal self-assigned this Jul 6, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

devin-ai-integration Bot and others added 2 commits July 6, 2026 12:14
…useless_conversion)

Co-Authored-By: pi li <songmqq@proton.me>
…lias conflicts (keep main's aliases)

Co-Authored-By: pi li <songmqq@proton.me>
@EeroEternal
EeroEternal merged commit bdc156b into main Jul 6, 2026
1 of 2 checks passed
@EeroEternal
EeroEternal deleted the devin/1783339838-xtrace-otlp-metrics branch July 6, 2026 14:36
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.

1 participant