UNPKG

2.06 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.wrapSpanContext = exports.isSpanContextValid = exports.isValidSpanId = exports.isValidTraceId = void 0;
4/*
5 * Copyright The OpenTelemetry Authors
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * https://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19var invalid_span_constants_1 = require("./invalid-span-constants");
20var NonRecordingSpan_1 = require("./NonRecordingSpan");
21var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
22var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
23function isValidTraceId(traceId) {
24 return VALID_TRACEID_REGEX.test(traceId) && traceId !== invalid_span_constants_1.INVALID_TRACEID;
25}
26exports.isValidTraceId = isValidTraceId;
27function isValidSpanId(spanId) {
28 return VALID_SPANID_REGEX.test(spanId) && spanId !== invalid_span_constants_1.INVALID_SPANID;
29}
30exports.isValidSpanId = isValidSpanId;
31/**
32 * Returns true if this {@link SpanContext} is valid.
33 * @return true if this {@link SpanContext} is valid.
34 */
35function isSpanContextValid(spanContext) {
36 return (isValidTraceId(spanContext.traceId) && isValidSpanId(spanContext.spanId));
37}
38exports.isSpanContextValid = isSpanContextValid;
39/**
40 * Wrap the given {@link SpanContext} in a new non-recording {@link Span}
41 *
42 * @param spanContext span context to be wrapped
43 * @returns a new non-recording {@link Span} with the provided context
44 */
45function wrapSpanContext(spanContext) {
46 return new NonRecordingSpan_1.NonRecordingSpan(spanContext);
47}
48exports.wrapSpanContext = wrapSpanContext;
49//# sourceMappingURL=spancontext-utils.js.map
\No newline at end of file