Skip to content

Commit 44096c8

Browse files
authored
[SDK] Allow metric instrument names to contain / characters (#2310)
1 parent b9776d6 commit 44096c8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

sdk/src/metrics/instrument_metadata_validator.cc

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace sdk
1717
{
1818
namespace metrics
1919
{
20-
// instrument-name = ALPHA 0*254 ("_" / "." / "-" / ALPHA / DIGIT)
21-
const std::string kInstrumentNamePattern = "[a-zA-Z][-_.a-zA-Z0-9]{0,254}";
20+
// instrument-name = ALPHA 0*254 ("_" / "." / "-" / "/" / ALPHA / DIGIT)
21+
const std::string kInstrumentNamePattern = "[a-zA-Z][-_./a-zA-Z0-9]{0,254}";
2222
//
2323
const std::string kInstrumentUnitPattern = "[\x01-\x7F]{0,63}";
2424
// instrument-unit = It can have a maximum length of 63 ASCII chars
@@ -49,9 +49,11 @@ bool InstrumentMetaDataValidator::ValidateName(nostd::string_view name) const
4949
{
5050
return false;
5151
}
52-
// subsequent chars should be either of alphabets, digits, underscore, minus, dot
53-
return !std::any_of(std::next(name.begin()), name.end(),
54-
[](char c) { return !isalnum(c) && c != '-' && c != '_' && c != '.'; });
52+
// subsequent chars should be either of alphabets, digits, underscore,
53+
// minus, dot, slash
54+
return !std::any_of(std::next(name.begin()), name.end(), [](char c) {
55+
return !isalnum(c) && (c != '-') && (c != '_') && (c != '.') && (c != '/');
56+
});
5557
#endif
5658
}
5759

sdk/test/metrics/instrument_metadata_validator_test.cc

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ TEST(InstrumentMetadataValidator, TestName)
2424
"123€AAA€BBB", // unicode characters
2525
"/\\sdsd", // string starting with special character
2626
"***sSSs", // string starting with special character
27+
"a\\broken\\path", // contains backward slash
2728
CreateVeryLargeString(25) + "X", // total 256 characters
2829
CreateVeryLargeString(26), // string much bigger than 255 characters
2930
};
@@ -37,6 +38,7 @@ TEST(InstrumentMetadataValidator, TestName)
3738
"s123", // starting with char, followed by numbers
3839
"dsdsdsd_-.", // string , and valid nonalphanumeric
3940
"d1234_-sDSDs.sdsd344", // combination of all valid characters
41+
"a/path/to/some/metric", // contains forward slash
4042
CreateVeryLargeString(5) + "ABCERTYG", // total 63 characters
4143
CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 characters
4244
CreateVeryLargeString(24) + "ABCDEFGHI", // total 254 characters

0 commit comments

Comments
 (0)