Skip to content

Commit ed0ba06

Browse files
legendecasobecnyvmarchaud
authored
fix(sdk-metrics-base): metrics name should be in the max length of 63 (#2495)
Co-authored-by: Bartlomiej Obecny <[email protected]> Co-authored-by: Valentin Marchaud <[email protected]>
1 parent faca317 commit ed0ba06

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,6 @@ export class Meter implements api.Meter {
350350
* @param name Name of metric to be created
351351
*/
352352
private _isValidName(name: string): boolean {
353-
return Boolean(name.match(/^[a-z][a-z0-9_.-]*$/i));
353+
return Boolean(name.match(/^[a-z][a-z0-9_.-]{0,62}$/i));
354354
}
355355
}

experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ describe('Meter', () => {
295295
const counter = meter.createCounter('name with invalid characters^&*(');
296296
assert.ok(counter instanceof api.NoopMetric);
297297
});
298+
299+
it('should return no op metric if name exceeded length of 63', () => {
300+
const counter = meter.createCounter('a'.repeat(63));
301+
assert.ok(counter instanceof CounterMetric);
302+
const counter2 = meter.createCounter('a'.repeat(64));
303+
assert.ok(counter2 instanceof api.NoopMetric);
304+
});
298305
});
299306
});
300307

0 commit comments

Comments
 (0)