diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts index 32f295694c..2ca48dfbf6 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts @@ -350,6 +350,6 @@ export class Meter implements api.Meter { * @param name Name of metric to be created */ private _isValidName(name: string): boolean { - return Boolean(name.match(/^[a-z][a-z0-9_.-]*$/i)); + return Boolean(name.match(/^[a-z][a-z0-9_.-]{0,62}$/i)); } } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts index b1e6389b5d..0fcc05ede3 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts @@ -295,6 +295,13 @@ describe('Meter', () => { const counter = meter.createCounter('name with invalid characters^&*('); assert.ok(counter instanceof api.NoopMetric); }); + + it('should return no op metric if name exceeded length of 63', () => { + const counter = meter.createCounter('a'.repeat(63)); + assert.ok(counter instanceof CounterMetric); + const counter2 = meter.createCounter('a'.repeat(64)); + assert.ok(counter2 instanceof api.NoopMetric); + }); }); });