UNPKG

1.96 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 { createContextKey } from '../context/context';
17import { NonRecordingSpan } from './NonRecordingSpan';
18/**
19 * span key
20 */
21var SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN');
22/**
23 * Return the span if one exists
24 *
25 * @param context context to get span from
26 */
27export function getSpan(context) {
28 return context.getValue(SPAN_KEY) || undefined;
29}
30/**
31 * Set the span on a context
32 *
33 * @param context context to use as parent
34 * @param span span to set active
35 */
36export function setSpan(context, span) {
37 return context.setValue(SPAN_KEY, span);
38}
39/**
40 * Remove current span stored in the context
41 *
42 * @param context context to delete span from
43 */
44export function deleteSpan(context) {
45 return context.deleteValue(SPAN_KEY);
46}
47/**
48 * Wrap span context in a NoopSpan and set as span in a new
49 * context
50 *
51 * @param context context to set active span on
52 * @param spanContext span context to be wrapped
53 */
54export function setSpanContext(context, spanContext) {
55 return setSpan(context, new NonRecordingSpan(spanContext));
56}
57/**
58 * Get the span context of the span if it exists.
59 *
60 * @param context context to get values from
61 */
62export function getSpanContext(context) {
63 var _a;
64 return (_a = getSpan(context)) === null || _a === void 0 ? void 0 : _a.spanContext();
65}
66//# sourceMappingURL=context-utils.js.map
\No newline at end of file