Skip to content

Commit 1a65aec

Browse files
authored
Limit character set according to spec (#3821)
1 parent 9b37202 commit 1a65aec

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/OpenTelemetry/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
* Fix instrument naming enforcement implementation to match the spec.
6+
([#3821](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3821))
7+
58
* Added support for loading environment variables from `IConfiguration` when
69
using the `MetricReaderOptions` & `BatchExportActivityProcessorOptions`
710
classes.

src/OpenTelemetry/Metrics/Builder/MeterProviderBuilderSdk.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace OpenTelemetry.Metrics
2424
internal sealed class MeterProviderBuilderSdk : MeterProviderBuilderBase
2525
{
2626
private static readonly Regex InstrumentNameRegex = new(
27-
@"^[a-zA-Z][-.\w]{0,62}$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
27+
@"^[a-z][a-z0-9-._]{0,62}$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
2828

2929
public MeterProviderBuilderSdk()
3030
{

test/OpenTelemetry.Tests/Metrics/MetricTestData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static IEnumerable<object[]> InvalidInstrumentNames
2828
new object[] { "1first-char-not-alphabetic" },
2929
new object[] { "invalid+separator" },
3030
new object[] { new string('m', 64) },
31+
new object[] { "a\xb5" }, // `\xb5` is the Micro character
3132
};
3233

3334
public static IEnumerable<object[]> ValidInstrumentNames
@@ -39,6 +40,7 @@ public static IEnumerable<object[]> ValidInstrumentNames
3940
new object[] { "my.metric" },
4041
new object[] { "my_metric2" },
4142
new object[] { new string('m', 63) },
43+
new object[] { "CaSe-InSeNsItIvE" },
4244
};
4345

4446
public static IEnumerable<object[]> InvalidHistogramBoundaries

0 commit comments

Comments
 (0)