From e9014a287c8ab8f6d6f4566791913b0b6c7fcae1 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 11 Aug 2023 00:49:47 -0700 Subject: [PATCH] Increase instrument name maximum length from 63 to 255 characters (#4434) --- CHANGELOG.md | 1 + sdk/metric/meter.go | 6 +++--- sdk/metric/meter_test.go | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53588f04d8b..ebfa8d5a9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Restrict `Meter`s in `go.opentelemetry.io/otel/sdk/metric` to only register and collect instruments it created. (#4333) - `PeriodicReader.Shutdown` and `PeriodicReader.ForceFlush` in `go.opentelemetry.io/otel/sdk/metric` now apply the periodic reader's timeout to the operation if the user provided context does not contain a deadline. (#4356, #4377) - Upgrade all use of `go.opentelemetry.io/otel/semconv` to use `v1.21.0`. (#4408) +- Increase instrument name maximum length from 63 to 255 characters. (#4434) ### Removed diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index caed7387c0a..9d2de67c594 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -28,7 +28,7 @@ import ( var ( // ErrInstrumentName indicates the created instrument has an invalid name. - // Valid names must consist of 63 or fewer characters including alphanumeric, _, ., -, and start with a letter. + // Valid names must consist of 255 or fewer characters including alphanumeric, _, ., -, and start with a letter. ErrInstrumentName = errors.New("invalid instrument name") ) @@ -252,8 +252,8 @@ func validateInstrumentName(name string) error { if len(name) == 0 { return fmt.Errorf("%w: %s: is empty", ErrInstrumentName, name) } - if len(name) > 63 { - return fmt.Errorf("%w: %s: longer than 63 characters", ErrInstrumentName, name) + if len(name) > 255 { + return fmt.Errorf("%w: %s: longer than 255 characters", ErrInstrumentName, name) } if !isAlpha([]rune(name)[0]) { return fmt.Errorf("%w: %s: must start with a letter", ErrInstrumentName, name) diff --git a/sdk/metric/meter_test.go b/sdk/metric/meter_test.go index 65f5acfa6c8..338d0d7a0e2 100644 --- a/sdk/metric/meter_test.go +++ b/sdk/metric/meter_test.go @@ -743,6 +743,11 @@ func TestMeterCreatesInstrumentsValidations(t *testing.T) { } func TestValidateInstrumentName(t *testing.T) { + const longName = "longNameOver255characters" + + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" testCases := []struct { name string @@ -776,8 +781,8 @@ func TestValidateInstrumentName(t *testing.T) { wantErr: fmt.Errorf("%w: name!: must only contain [A-Za-z0-9_.-]", ErrInstrumentName), }, { - name: "someverylongnamewhichisover63charactersbutallofwhichmatchtheregexp", - wantErr: fmt.Errorf("%w: someverylongnamewhichisover63charactersbutallofwhichmatchtheregexp: longer than 63 characters", ErrInstrumentName), + name: longName, + wantErr: fmt.Errorf("%w: %s: longer than 255 characters", ErrInstrumentName, longName), }, }