Skip to content

Commit

Permalink
fix(sdk-metrics-base): metrics name should be in the max length of 63 (
Browse files Browse the repository at this point in the history
…#2495)

Co-authored-by: Bartlomiej Obecny <[email protected]>
Co-authored-by: Valentin Marchaud <[email protected]>
  • Loading branch information
3 people authored Oct 10, 2021
1 parent faca317 commit ed0ba06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down

0 comments on commit ed0ba06

Please sign in to comment.