feat: metrics by jpnurmi · Pull Request #1498 · getsentry/sentry-native

and others added 3 commits

January 29, 2026 16:01
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@jpnurmi jpnurmi changed the title feat: metrics WIP: feat: metrics

Jan 29, 2026
Per the Sentry metrics specification, counter metrics should use 64-bit
signed integers. This is consistent with sentry_value_new_int64 /
sentry_value_as_int64 in sentry.h.

Also refactored internal record_metric to pass sentry_value_t instead
of double, allowing proper type preservation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@jpnurmi

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The value parameter was not being decremented when metrics were disabled,
causing a memory leak.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@jpnurmi @claude

Per the developer docs, units are only used for distribution and gauge
metrics, not counters.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Split blocking shutdown and force_flush operations into begin (non-blocking
trigger) and wait (blocking completion) phases. This allows logs and metrics
operations to run in parallel in sentry_flush() and sentry_close().

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add metrics integration tests to match the existing logs test coverage:
- test_metrics_threaded: concurrent metrics from 50 threads
- test_metrics_global_and_local_attributes_merge: global + local attributes
- test_metrics_discarded_on_crash_no_backend: metrics discarded without backend
- test_metrics_on_crash: parameterized test for inproc/breakpad backends

Also refactor thread creation in example.c into a shared run_threads() helper
function used by both logs-threads and metrics-threads commands.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Allow reusing attribute objects across multiple log calls, as documented.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Global attributes set via sentry_set_attribute() were not being merged
into metrics. Now scope attributes are merged with user attributes
having priority on conflicts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@jpnurmi

@jpnurmi

@jpnurmi jpnurmi marked this pull request as ready for review

February 2, 2026 16:02

@jpnurmi jpnurmi changed the title WIP: feat: metrics feat: metrics

Feb 2, 2026

cursor[bot]

@jpnurmi

@jpnurmi

sentry[bot]

cursor[bot]

@jpnurmi

@jpnurmi

The split of force_flush into _begin() + _wait() introduced a race where
_begin() wakes the batcher thread, but _wait() could return early if the
batcher thread wins the race to acquire the flushing lock. This could
cause sentry_flush() to return before data was actually sent.

Fix by making sentry__batcher_flush return bool indicating success, and
loop in _wait() until a flush actually completes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

mujacica

jpnurmi added a commit to getsentry/sentry-docs that referenced this pull request

Feb 3, 2026

@jpnurmi @claude

tustanivsky

JoshuaMoelans

Co-authored-by: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com>

@jpnurmi

cursor[bot]

@jpnurmi

cursor[bot]

@jpnurmi

sentry[bot]

@jpnurmi

cursor[bot]

tustanivsky

@jpnurmi jpnurmi deleted the jpnurmi/feat/metrics branch

February 5, 2026 10:38