Add metrics with increment, gauge, and distribution support#78
Merged
dharrigan merged 4 commits intogetsentry:masterfrom Feb 18, 2026
Merged
Add metrics with increment, gauge, and distribution support#78dharrigan merged 4 commits intogetsentry:masterfrom
dharrigan merged 4 commits intogetsentry:masterfrom
Conversation
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) |
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
Looks like, reduce-kv on nil returns the initial value ([]) - it does not throw a NullPointerException. So, the fix might be not needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.