1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-03 00:27:03 +02:00

Allow '/' character in instrument names (#4501)

* Allow '/' character in instrument names

* Add changelog

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Aaron Abbott
2023-09-13 12:01:34 -04:00
committed by GitHub
parent 4242228103
commit bcbee2ac1a
3 changed files with 11 additions and 4 deletions

View File

@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased] ## [Unreleased]
### Changed
- Allow '/' characters in metric instrument names. (#4501)
## [1.18.0/0.41.0/0.0.6] 2023-09-12 ## [1.18.0/0.41.0/0.0.6] 2023-09-12
This release drops the compatibility guarantee of [Go 1.19]. This release drops the compatibility guarantee of [Go 1.19].

View File

@ -28,7 +28,7 @@ import (
var ( var (
// ErrInstrumentName indicates the created instrument has an invalid name. // ErrInstrumentName indicates the created instrument has an invalid name.
// Valid names must consist of 255 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") ErrInstrumentName = errors.New("invalid instrument name")
) )
@ -262,8 +262,8 @@ func validateInstrumentName(name string) error {
return nil return nil
} }
for _, c := range name[1:] { for _, c := range name[1:] {
if !isAlphanumeric(c) && c != '_' && c != '.' && c != '-' { if !isAlphanumeric(c) && c != '_' && c != '.' && c != '-' && c != '/' {
return fmt.Errorf("%w: %s: must only contain [A-Za-z0-9_.-]", ErrInstrumentName, name) return fmt.Errorf("%w: %s: must only contain [A-Za-z0-9_.-/]", ErrInstrumentName, name)
} }
} }
return nil return nil

View File

@ -775,9 +775,12 @@ func TestValidateInstrumentName(t *testing.T) {
{ {
name: "nam.", name: "nam.",
}, },
{
name: "nam/e",
},
{ {
name: "name!", name: "name!",
wantErr: fmt.Errorf("%w: name!: must only contain [A-Za-z0-9_.-]", ErrInstrumentName), wantErr: fmt.Errorf("%w: name!: must only contain [A-Za-z0-9_.-/]", ErrInstrumentName),
}, },
{ {
name: longName, name: longName,