Skip to content

Commit 6da8fad

Browse files
committed
Record error when necessary on labeled metric
As it is right now it is not possible to add the testGetNumRecordedErrors API to labeled metrics. All properties on the LabeledMetricType must be of the same type as the submetric.
1 parent 68345ab commit 6da8fad

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

glean/src/core/metrics/types/labeled.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type StringMetricType from "./string.js";
99
import type MetricsDatabase from "../database";
1010
import type { JSONValue } from "../../utils.js";
1111
import { Metric } from "../metric.js";
12+
import { ErrorType, recordError, testGetNumRecordedErrors } from "../../error_recording.js";
1213

1314
/**
1415
* This is an internal metric representation for labeled metrics.
@@ -127,13 +128,19 @@ export async function getValidDynamicLabel(metricsDatabase: MetricsDatabase, met
127128
if (numUsedKeys >= MAX_LABELS) {
128129
hitError = true;
129130
} else if (metric.dynamicLabel.length > MAX_LABEL_LENGTH) {
130-
console.error(`label length ${metric.dynamicLabel.length} exceeds maximum of ${MAX_LABEL_LENGTH}`);
131131
hitError = true;
132-
// TODO: record error in bug 1682574
132+
await recordError(
133+
metric,
134+
ErrorType.InvalidLabel,
135+
`Label length ${metric.dynamicLabel.length} exceeds maximum of ${MAX_LABEL_LENGTH}.`
136+
);
133137
} else if (!LABEL_REGEX.test(metric.dynamicLabel)) {
134-
console.error(`label must be snake_case, got '${metric.dynamicLabel}'`);
135138
hitError = true;
136-
// TODO: record error in bug 1682574
139+
await recordError(
140+
metric,
141+
ErrorType.InvalidLabel,
142+
`Label must be snake_case, got '${metric.dynamicLabel}'.`
143+
);
137144
}
138145

139146
return (hitError)

0 commit comments

Comments
 (0)