UNPKG

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