Skip to content

Add metrics with increment, gauge, and distribution support#78

Merged
dharrigan merged 4 commits intogetsentry:masterfrom
abogoyavlensky:feature-metrics
Feb 18, 2026
Merged

Add metrics with increment, gauge, and distribution support#78
dharrigan merged 4 commits intogetsentry:masterfrom
abogoyavlensky:feature-metrics

Conversation

@abogoyavlensky
Copy link
Contributor

No description provided.

@abogoyavlensky abogoyavlensky changed the title Feature metrics Add metrics with increment, gauge, and distribution support Feb 16, 2026
@abogoyavlensky
Copy link
Contributor Author

Resolves #79

Comment on lines +74 to +80
(defn- attrs->params
"Converts a Clojure map of attributes to SentryMetricsParameters.
Reuses the SentryAttribute type detection pattern from sentry-clj.logging."
^SentryMetricsParameters [attrs]
(let [attributes (reduce-kv
(fn [acc k v]
(let [attr-name (name k)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The attrs->params function calls reduce-kv on attrs without a nil check, which can cause a NullPointerException if metric functions are called with nil attributes.
Severity: HIGH

Suggested Fix

Before calling reduce-kv on the attrs parameter within the attrs->params function, add a check to ensure attrs is not nil. If it is nil, return an empty collection to avoid the NullPointerException. A (when (map? attrs) ...) guard would be an effective way to handle this.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry_clj/metrics.clj#L74-L80

Potential issue: The 4-arity versions of the `increment`, `gauge`, and `distribution`
functions pass their `attrs` argument directly to the `attrs->params` helper. This
helper function uses `reduce-kv` on `attrs` without first checking if it is `nil`.
Unlike `reduce`, `reduce-kv` throws a `NullPointerException` when called on a `nil`
collection. Therefore, if a user calls one of these metric functions with `nil` for the
`attrs` parameter, for example `(increment "metric" 1.0 :second nil)`, the application
will crash with a `NullPointerException`. This can happen in legitimate scenarios, such
as when building function calls dynamically.

Copy link
Contributor Author

@abogoyavlensky abogoyavlensky Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like, reduce-kv on nil returns the initial value ([]) - it does not throw a NullPointerException. So, the fix might be not needed.

@dharrigan dharrigan merged commit 4e08c7c into getsentry:master Feb 18, 2026
3 checks passed
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