UNPKG

1.66 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 */
16import { INVALID_SPANID, INVALID_TRACEID } from './invalid-span-constants';
17import { NonRecordingSpan } from './NonRecordingSpan';
18var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
19var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
20export function isValidTraceId(traceId) {
21 return VALID_TRACEID_REGEX.test(traceId) && traceId !== INVALID_TRACEID;
22}
23export function isValidSpanId(spanId) {
24 return VALID_SPANID_REGEX.test(spanId) && spanId !== INVALID_SPANID;
25}
26/**
27 * Returns true if this {@link SpanContext} is valid.
28 * @return true if this {@link SpanContext} is valid.
29 */
30export function isSpanContextValid(spanContext) {
31 return (isValidTraceId(spanContext.traceId) && isValidSpanId(spanContext.spanId));
32}
33/**
34 * Wrap the given {@link SpanContext} in a new non-recording {@link Span}
35 *
36 * @param spanContext span context to be wrapped
37 * @returns a new non-recording {@link Span} with the provided context
38 */
39export function wrapSpanContext(spanContext) {
40 return new NonRecordingSpan(spanContext);
41}
42//# sourceMappingURL=spancontext-utils.js.map
\No newline at end of file