UNPKG

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