Skip to content

OpenTelemetry metrics support#824

Open
tewbo wants to merge 30 commits into
ydb-platform:mainfrom
tewbo:opentelemetry-metrics-support
Open

OpenTelemetry metrics support#824
tewbo wants to merge 30 commits into
ydb-platform:mainfrom
tewbo:opentelemetry-metrics-support

Conversation

@tewbo
Copy link
Copy Markdown
Contributor

@tewbo tewbo commented May 11, 2026

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

The SDK supports OpenTelemetry tracing, but it does not expose client-side OpenTelemetry metrics for YDB operations, retries, or query session pools.

What is the new behavior?

This PR adds OpenTelemetry metrics support for the YDB Python SDK.

Added metrics include:

  • db.client.operation.duration for client operation latency
  • ydb.client.operation.failed for failed client operations
  • ydb.query.session.create_time for query session creation latency
  • ydb.query.session.pending_requests for session pool wait queue size
  • ydb.query.session.timeouts for session acquisition timeouts
  • ydb.query.session.count for current session pool state by idle / used
  • ydb.query.session.max for configured session pool size
  • ydb.client.retry.duration for total retry operation duration
  • ydb.client.retry.attempts for number of retry attempts per logical operation

The public OpenTelemetry API now includes:

  • enable_metrics(meter_provider=None)
  • disable_metrics()

Metrics are independent from tracing, but both can be enabled together. YDB operation telemetry now uses a composite operation object so tracing spans and metrics can be recorded for the same SDK operation without adding an extra span level.

This PR also updates the OpenTelemetry example to export both traces and metrics through OTLP, and documents the metrics setup, emitted instruments, and metric attributes.

Other information

The OpenTelemetry tests were moved from tests/tracing to tests/opentelemetry, and metrics tests were added using OpenTelemetry SDK in-memory metric readers.

@tewbo tewbo marked this pull request as draft May 11, 2026 04:26
@tewbo tewbo marked this pull request as ready for review May 19, 2026 14:33
Comment thread examples/opentelemetry/metrics_views.py Outdated
Comment thread examples/opentelemetry/metrics_views.py Outdated
Comment thread examples/opentelemetry/metrics_views.py Outdated
Comment thread ydb/opentelemetry/metrics.py
Comment thread ydb/opentelemetry/metrics.py
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py Outdated
Comment thread ydb/opentelemetry/metrics.py Outdated
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.

2 participants