sentry-setup-metrics▌
getsentry/sentry-agent-skills · updated Apr 8, 2026
Configure Sentry's custom metrics for tracking counters, gauges, and distributions.
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
Important: The SDK versions, API names, and code samples below are examples. Always verify against docs.sentry.io before implementing, as APIs and minimum versions may have changed.
Quick Reference
Check Sentry Metrics Getting Started for the full list of supported SDKs and minimum versions. Examples below use JavaScript and Python:
| Platform | Min SDK | API | Status |
|---|---|---|---|
| JavaScript | 10.25.0+ | Sentry.metrics.* |
Open Beta |
| Python | 2.44.0+ | sentry_sdk.metrics.* |
Open Beta |
| Ruby | 6.3.0+ | Sentry.metrics.* |
Open Beta |
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
Ruby Setup
Metrics are enabled by default in SDK 6.3.0+.
Counter
Sentry.metrics.count("api_call", 1, attributes: { endpoint: "/api/users" })
Gauge
Sentry.metrics.gauge("queue_depth", 42, attributes: { queue: "jobs" })
Distribution
Sentry.metrics.distribution("response_time", 187.5, unit: "millisecond", attributes: { endpoint: "/api/products" })
Best Practices
- Stay under 2KB per metric: Each metric event has a 2KB size limit — keep attribute sets concise
- Namespaced names:
api.request.duration, notduration - Flush on exit: Call
Sentry.flush()before process exit
Verification
After adding a metric, trigger the code path that emits it and check the Sentry Metrics dashboard (Explore > Metrics). Metrics may take a few minutes to appear due to buffer flushing.
Troubleshooting
| Issue | Solution |
|---|---|
| Metrics not appearing | Verify SDK version, check DSN, wait for buffer flush |
| Metric dropped silently | Check that metric event is under 2KB size limit — reduce attributes |
| Too many metrics | Use beforeSendMetric to filter |
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★68 reviews- ★★★★★Ama Jain· Dec 28, 2024
Keeps context tight: sentry-setup-metrics is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Omar Dixit· Dec 28, 2024
sentry-setup-metrics reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Hana Abebe· Dec 20, 2024
Registry listing for sentry-setup-metrics matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Aanya Khan· Dec 16, 2024
sentry-setup-metrics has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Daniel Sanchez· Dec 4, 2024
Registry listing for sentry-setup-metrics matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Ishan Flores· Dec 4, 2024
sentry-setup-metrics fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Hana Mensah· Nov 23, 2024
Useful defaults in sentry-setup-metrics — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Meera Perez· Nov 19, 2024
sentry-setup-metrics has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Naina Bansal· Nov 19, 2024
I recommend sentry-setup-metrics for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Harper Khanna· Nov 15, 2024
sentry-setup-metrics fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
showing 1-10 of 68