Skip to content

Commit

Permalink
Increase instrument name maximum length from 63 to 255 characters (#4434
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MrAlias authored Aug 11, 2023
1 parent a9552aa commit e9014a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions sdk/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions sdk/metric/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),
},
}

Expand Down

0 comments on commit e9014a2

Please sign in to comment.