Skip to content

Add opentelemetry metrics support - #14700

Merged
Turbo87 merged 11 commits into
rust-lang:mainfrom
Turbo87:add-otel-metrics
Sep 18, 2026
Merged

Turbo87 merged 11 commits into
rust-lang:mainfrom
Turbo87:add-otel-metrics

Conversation

@Turbo87

@Turbo87 Turbo87 commented Sep 16, 2026

Copy link
Copy Markdown
Member

This PR adds opentelemetry metrics support to the application.

It can be enabled by setting the OTEL_EXPORTER_OTLP_ENDPOINT environment variable and all of the other necessary environment variables read by the opentelemetry crate family.

The implementation is intentionally not coupled to Datadog and can easily be configure to point to a different OTLP server. Note that once OTEL_EXPORTER_OTLP_ENDPOINT is enabled, the custom Datadog metrics exporter is disabled to avoid conflicting reports.

Related

@Turbo87 Turbo87 added the C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear label Sep 16, 2026
@Turbo87
Turbo87 requested a review from a team September 16, 2026 21:30
@Turbo87 Turbo87 changed the title Migrate metrics to opentelemetry Add opentelemetry metrics support Sep 16, 2026
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

Select OTLP metrics export when either standard endpoint variable is present. Build the provider with deployment and Heroku resource attributes, and fall back to a no-op provider when export initialization fails.
Create the server meter at startup and retain its provider for the process lifetime. Track each request with the OpenTelemetry HTTP method and scheme attributes, and inject no-op meters into the general test harness.
Do not construct or inject the legacy Datadog client when OTLP is selected. Skip the service metrics task with an OTLP-specific message so initialization failures do not silently reactivate direct submission.
Introduce `SharedMetrics` and observe idle and used connection counts for each configured server pool. Primary and replica callbacks use pool-name and connection-state attributes so the SDK merges them into one metric stream.
Record the unavailable preferred pool whenever either read path falls back to its alternative. The OpenTelemetry counter runs alongside the existing Prometheus metric during expansion.
@rustbot

rustbot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Load crate, version, and queued-job counts into a complete snapshot before recording Prometheus gauges. The private endpoint and direct Datadog submission continue to use the same metric families without publishing partial query results.
The background worker retains its meter provider and records crate and version counts from complete service snapshots through `WorkerMetrics`. Collection continues when legacy direct Datadog submission is disabled, while configured submissions reuse the same snapshot.
Worker metrics share the database-pool observable instruments used by the server. Worker startup registers its pool with the `worker` name, and integration coverage verifies all three pool names.
The serial service-metrics task retains previously observed queue labels and adds zero-valued entries when a queue disappears. Worker metrics record the completed snapshot through the existing priority and job attributes while legacy output continues to use the same values.
Successful tar.gz and zip uploads now record archive size and upload duration through WorkerMetrics with the existing format attribute. The legacy direct Datadog submission remains active when configured during the migration.
@Turbo87

Turbo87 commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

I'm gonna try this out on staging. The code is essentially disabled unless the relevant env vars are set, so even if this gets deployed to production it shouldn't have an immediate impact.

@Turbo87
Turbo87 merged commit cebd129 into rust-lang:main Sep 18, 2026
12 checks passed
@Turbo87
Turbo87 deleted the add-otel-metrics branch September 18, 2026 09:07
@Turbo87

Turbo87 commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

staging test was successful. everything appears to be working as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants