UNPKG

1.85 kBJavaScriptView Raw
1/*
2 * Copyright The OpenTelemetry Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16var VALID_KEY_CHAR_RANGE = '[_0-9a-z-*/]';
17var VALID_KEY = "[a-z]" + VALID_KEY_CHAR_RANGE + "{0,255}";
18var VALID_VENDOR_KEY = "[a-z0-9]" + VALID_KEY_CHAR_RANGE + "{0,240}@[a-z]" + VALID_KEY_CHAR_RANGE + "{0,13}";
19var VALID_KEY_REGEX = new RegExp("^(?:" + VALID_KEY + "|" + VALID_VENDOR_KEY + ")$");
20var VALID_VALUE_BASE_REGEX = /^[ -~]{0,255}[!-~]$/;
21var INVALID_VALUE_COMMA_EQUAL_REGEX = /,|=/;
22/**
23 * Key is opaque string up to 256 characters printable. It MUST begin with a
24 * lowercase letter, and can only contain lowercase letters a-z, digits 0-9,
25 * underscores _, dashes -, asterisks *, and forward slashes /.
26 * For multi-tenant vendor scenarios, an at sign (@) can be used to prefix the
27 * vendor name. Vendors SHOULD set the tenant ID at the beginning of the key.
28 * see https://www.w3.org/TR/trace-context/#key
29 */
30export function validateKey(key) {
31 return VALID_KEY_REGEX.test(key);
32}
33/**
34 * Value is opaque string up to 256 characters printable ASCII RFC0020
35 * characters (i.e., the range 0x20 to 0x7E) except comma , and =.
36 */
37export function validateValue(value) {
38 return (VALID_VALUE_BASE_REGEX.test(value) &&
39 !INVALID_VALUE_COMMA_EQUAL_REGEX.test(value));
40}
41//# sourceMappingURL=tracestate-validators.js.map
\No newline at end of file