fix(sdk-metrics-base): metrics name should be in the max length of 63 (#2495)

Co-authored-by: Bartlomiej Obecny <bobecny@gmail.com>
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
This commit is contained in:
legendecas 2021-10-11 02:59:43 +08:00 committed by GitHub
parent faca317da1
commit ed0ba063ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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));
}
}

View File

@ -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);
});
});
});