Skip to content

feat: Add trace metrics support#997

Draft
jjbayer wants to merge 6 commits intomasterfrom
feat/trace-metrics
Draft

feat: Add trace metrics support#997
jjbayer wants to merge 6 commits intomasterfrom
feat/trace-metrics

Conversation

@jjbayer
Copy link
Member

@jjbayer jjbayer commented Feb 17, 2026

Implement trace metrics per the Sentry SDK telemetry spec, enabling SDKs to capture and transmit quantitative performance data (counters, gauges, distributions) associated with traces.

The implementation mirrors the existing structured logs architecture:

  • TraceMetric/TraceMetricType protocol types in sentry-types
  • TraceMetrics envelope item container with serialization/deserialization
  • MetricsBatcher with background worker thread (100-item / 5s flush)
  • Feature-gated behind metrics feature flag
  • Public API: metrics_count(), metrics_gauge(), metrics_distribution()
  • before_send_metric callback and enable_metrics client option
  • Trace context (trace_id, span_id) and user attributes from scope

Description

Issues

Reminders

Implement trace metrics per the Sentry SDK telemetry spec, enabling
SDKs to capture and transmit quantitative performance data (counters,
gauges, distributions) associated with traces.

The implementation mirrors the existing structured logs architecture:
- TraceMetric/TraceMetricType protocol types in sentry-types
- TraceMetrics envelope item container with serialization/deserialization
- MetricsBatcher with background worker thread (100-item / 5s flush)
- Feature-gated behind `metrics` feature flag
- Public API: metrics_count(), metrics_gauge(), metrics_distribution()
- before_send_metric callback and enable_metrics client option
- Trace context (trace_id, span_id) and user attributes from scope

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Feb 17, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Add trace metrics support ([#997](https://github.com/getsentry/sentry-rust/pull/997))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against eec8f9c

jjbayer and others added 5 commits February 17, 2026 15:22
Replace the duplicate LogsBatcher and MetricsBatcher with a single
generic Batcher<T> that handles both log and metric batching using
a function pointer for envelope item conversion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Only the configured fraction of metrics is submitted. Sampled metrics
are annotated with a `sentry.client_sample_rate` attribute so the
server can extrapolate.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
A sample rate of 0.0 now disables metrics entirely, removing the
need for a separate enable_metrics boolean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

Comments