Setup Sentry Metrics in any project. Use when asked to add custom metrics, track counters/gauges/distributions, or instrument application performance. Supports JavaScript and Python.
Setup Sentry Metrics
Configure Sentry's custom metrics for tracking counters, gauges, and distributions.
Invoke This Skill When
- User asks to "add Sentry metrics" or "track custom metrics"
- User wants counters, gauges, or distributions
- User asks about
Sentry.metricsorsentry_sdk.metrics
Quick Reference
| Platform | Min SDK | API |
|---|---|---|
| JavaScript | 10.25.0+ | Sentry.metrics.* |
| Python | 2.44.0+ | sentry_sdk.metrics.* |
Note: Ruby does not have metrics support.
Metric Types
| Type | Purpose | Example Use Cases |
|---|---|---|
| Counter | Cumulative counts | API calls, clicks, errors |
| Gauge | Point-in-time values | Queue depth, memory, connections |
| Distribution | Statistical values | Response times, cart amounts |
JavaScript Setup
Metrics are enabled by default in SDK 10.25.0+.
Counter
Sentry.metrics.count("api_call", 1, {
attributes: { endpoint: "/api/users", status_code: 200 },
});
Gauge
Sentry.metrics.gauge("queue_depth", 42, {
unit: "none",
attributes: { queue: "jobs" },
});
Distribution
Sentry.metrics.distribution("response_time", 187.5, {
unit: "millisecond",
attributes: { endpoint: "/api/products" },
});
Filtering (optional)
Sentry.init({
beforeSendMetric: (metric) => {
if (metric.attributes?.sensitive) return null;
return metric;
},
});
Python Setup
Metrics are enabled by default in SDK 2.44.0+.
Counter
sentry_sdk.metrics.count("api_call", 1, attributes={"endpoint": "/api/users"})
Gauge
sentry_sdk.metrics.gauge("queue_depth", 42, attributes={"queue": "jobs"})
Distribution
sentry_sdk.metrics.distribution(
"response_time", 187.5,
unit="millisecond",
attributes={"endpoint": "/api/products"}
)
Filtering (optional)
def before_send_metric(metric, hint):
if metric.get("attributes", {}).get("sensitive"):
return None
return metric
sentry_sdk.init(dsn="YOUR_DSN", before_send_metric=before_send_metric)
Common Units
| Category | Values |
|---|---|
| Time | millisecond, second, minute, hour |
| Size | byte, kilobyte, megabyte |
| Currency | usd, eur, gbp |
| Other | none, percent, ratio |
Timing Helper Pattern
JavaScript
async function withTiming(name, fn, attrs = {}) {
const start = performance.now();
try { return await fn(); }
finally {
Sentry.metrics.distribution(name, performance.now() - start, {
unit: "millisecond", attributes: attrs,
});
}
}
Python
import time, sentry_sdk
def track_duration(name, **attrs):
def decorator(fn):
def wrapper(*args, **kwargs):
start = time.time()
try: return fn(*args, **kwargs)
finally:
sentry_sdk.metrics.distribution(
name, (time.time() - start) * 1000,
unit="millisecond", attributes=attrs
)
return wrapper
return decorator
Best Practices
- Low cardinality: Avoid user IDs, request IDs in attributes
- Namespaced names:
api.request.duration, notduration - Flush on exit: Call
Sentry.flush()before process exit
Troubleshooting
| Issue | Solution |
|---|---|
| Metrics not appearing | Verify SDK version, check DSN, wait for buffer flush |
| High cardinality warning | Remove unique IDs from attributes |
| Too many metrics | Use beforeSendMetric to filter |
You Might Also Like
Related Skills

create-pr
Creates GitHub pull requests with properly formatted titles that pass the check-pr-title CI validation. Use when creating PRs, submitting changes for review, or when the user says /pr or asks to create a pull request.
n8n-io
electron-chromium-upgrade
Guide for performing Chromium version upgrades in the Electron project. Use when working on the roller/chromium/main branch to fix patch conflicts during `e sync --3`. Covers the patch application workflow, conflict resolution, analyzing upstream Chromium changes, and proper commit formatting for patch fixes.
electron
pr-creator
Use this skill when asked to create a pull request (PR). It ensures all PRs follow the repository's established templates and standards.
google-gemini
clawdhub
Use the ClawdHub CLI to search, install, update, and publish agent skills from clawdhub.com. Use when you need to fetch new skills on the fly, sync installed skills to latest or a specific version, or publish new/updated skill folders with the npm-installed clawdhub CLI.
moltbot
tmux
Remote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
moltbot
create-pull-request
Create a GitHub pull request following project conventions. Use when the user asks to create a PR, submit changes for review, or open a pull request. Handles commit analysis, branch management, and PR creation using the gh CLI tool.
cline