From f2fc0d8787a82f33b1ce7e315759ddc61caf4f52 Mon Sep 17 00:00:00 2001 From: Aaron Abbott Date: Thu, 21 Sep 2023 04:02:50 -0400 Subject: [PATCH] fix(sdk-metrics): allow instrument names to contain '/' (#4155) --- CHANGELOG.md | 2 ++ packages/sdk-metrics/src/InstrumentDescriptor.ts | 2 +- packages/sdk-metrics/test/util.ts | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53987c4169..ad5c780983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :bug: (Bug Fix) +* fix(sdk-metrics): allow instrument names to contain '/' [#4155](https://github.com/open-telemetry/opentelemetry-js/pull/4155) + ### :books: (Refine Doc) ### :house: (Internal) diff --git a/packages/sdk-metrics/src/InstrumentDescriptor.ts b/packages/sdk-metrics/src/InstrumentDescriptor.ts index ac742fc0ee..f0053f9c39 100644 --- a/packages/sdk-metrics/src/InstrumentDescriptor.ts +++ b/packages/sdk-metrics/src/InstrumentDescriptor.ts @@ -88,7 +88,7 @@ export function isDescriptorCompatibleWith( // ASCII string with a length no greater than 255 characters. // NB: the first character counted separately from the rest. -const NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,254}$/i; +const NAME_REGEXP = /^[a-z][a-z0-9_.\-/]{0,254}$/i; export function isValidName(name: string): boolean { return name.match(NAME_REGEXP) != null; } diff --git a/packages/sdk-metrics/test/util.ts b/packages/sdk-metrics/test/util.ts index ef081cf67a..338a2f3978 100644 --- a/packages/sdk-metrics/test/util.ts +++ b/packages/sdk-metrics/test/util.ts @@ -67,7 +67,15 @@ export const defaultInstrumentationScope: InstrumentationScope = { }; export const invalidNames = ['', 'a'.repeat(256), '1a', '-a', '.a', '_a']; -export const validNames = ['a', 'a'.repeat(255), 'a1', 'a-1', 'a.1', 'a_1']; +export const validNames = [ + 'a', + 'a'.repeat(255), + 'a1', + 'a-1', + 'a.1', + 'a_1', + 'a/1', +]; export const commonValues: number[] = [1, -1, 1.0, Infinity, -Infinity, NaN]; export const commonAttributes: MetricAttributes[] = [