Conversation
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>
422c6ad to
875c3d9
Compare
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>
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>
SDKs "should offer constants or similar that help customers send in units we support" as specified in the developer docs. See: - https://develop.sentry.dev/sdk/telemetry/metrics/ - https://develop.sentry.dev/sdk/telemetry/attributes/#units Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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>
48664ff to
725b062
Compare
|
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>
Document metrics support for the Native SDK being added in getsentry/sentry-native#1498. Co-Authored-By: Claude <noreply@anthropic.com>
| * Records a counter metric. Counters track incrementing values like | ||
| * request counts or error counts. | ||
| */ | ||
| SENTRY_EXPERIMENTAL_API sentry_metrics_result_t sentry_metrics_count( |
There was a problem hiding this comment.
Good question. Some SDKs have a unit argument for the counter, while others don't. I also added it there at first, but decided to leave it out because it says in the docs:
The unit of measurement (only used for
distributionandgauge)
https://develop.sentry.dev/sdk/telemetry/metrics/#method-signatures
There was a problem hiding this comment.
The unit argument was removed from Cocoa:
During revision of the Method Signatures of the metrics API in the develop docs it was surfaced to me that count metrics do not accept a Metric Unit.
There was a problem hiding this comment.
@tustanivsky Are you ok with leaving this as is? See Sentry Cocoa 9.4.0:
Breaking Changes
Sentry.metrics.count(..)does not support units, therefore the API was incorrectly defined. This breaking change applies to a method marked as experimental. (#7358)
JoshuaMoelans
left a comment
There was a problem hiding this comment.
nice work, LGTM! just one small nit on a docstring, and a follow-up for cleaning up our integration test structure
| split_log_request_cond, | ||
| is_feedback_envelope, | ||
| is_logs_envelope, | ||
| is_metrics_envelope, |
There was a problem hiding this comment.
(idea): this integration test file is becoming huge, maybe we should start splitting it up (e.g., additional files for metrics/logs/traces/proxy). I can create a follow-up PR 🧹
Co-authored-by: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Summary
Implements the Sentry Metrics feature for the native SDK, allowing applications to record counter, gauge, and distribution metrics that are batched and sent to Sentry: https://develop.sentry.dev/sdk/telemetry/metrics/.
Closes #1453
Features
before_send_metriccallback for filtering or modifying metrics before sendingSENTRY_UNIT_*constants for common telemetry units (byte, kilobyte, millisecond, second, etc.)sentry_flush()andsentry_close()Public API
Considerations
The current API requires passing
sentry_value_new_null()when no custom attributes are needed. An alternative would be to provide simplified variants without the attributes parameter (e.g.,sentry_metrics_count()) alongside explicit variants (e.g.,sentry_metrics_count_with_attributes()). Feedback welcome on which approach is preferred.Dependenciesref(logs): extract reusable batcher for metrics #1495ref(logs): extract attribute helpers for metrics #1497Test plan
tests/unit/test_metrics.c)tests/test_integration_http.py)🤖 Generated with Claude Code