Skip to content

Commit 0d2c2e7

Browse files
committed
refactor(metrics): skip Sentry metrics in non-production environments
1 parent bbbb0b9 commit 0d2c2e7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/metrics.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Sentry from "@sentry/browser";
22
import { getCurrentVersionSlug, getUrlConfig, parseRoute } from "./routing";
3-
import { RUNNING_MODE } from "./utils/env";
3+
import { isProd, RUNNING_MODE } from "./utils/env";
44

55
/**
66
* Metric attributes type for Sentry metrics.
@@ -45,6 +45,7 @@ export const metrics = {
4545
* This sends a delta to Sentry without local accumulation.
4646
*/
4747
count(name: string, value: number = 1, attributes: MetricAttributes = {}) {
48+
if (!isProd) return;
4849
Sentry.metrics.count(name, value, {
4950
attributes: { ...getCommonAttributes(), ...attributes },
5051
});
@@ -54,6 +55,7 @@ export const metrics = {
5455
* Track current values or state (e.g., resource usage, resolved version).
5556
*/
5657
gauge(name: string, value: number, attributes: MetricAttributes = {}) {
58+
if (!isProd) return;
5759
Sentry.metrics.gauge(name, value, {
5860
attributes: { ...getCommonAttributes(), ...attributes },
5961
});
@@ -63,6 +65,7 @@ export const metrics = {
6365
* Track distributions for statistical analysis (e.g., durations, latency).
6466
*/
6567
distribution(name: string, value: number, attributes: MetricAttributes = {}) {
68+
if (!isProd) return;
6669
Sentry.metrics.distribution(name, value, {
6770
attributes: { ...getCommonAttributes(), ...attributes },
6871
});

0 commit comments

Comments
 (0)