UNPKG

1.73 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright 2018 Google LLC
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 * http://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 });
18const semver = require("semver");
19const useAsyncHooks = semver.satisfies(process.version, '>=8'); //&&
20// !!process.env.GCLOUD_TRACE_NEW_CONTEXT;
21const cls = useAsyncHooks
22 ? require('./cls-ah')
23 : require('continuation-local-storage');
24const TRACE_NAMESPACE = 'opencensus.io';
25/**
26 * Stack traces are captured when a root span is started. Because the stack
27 * trace height varies on the context propagation mechanism, to keep published
28 * stack traces uniform we need to remove the top-most frames when using the
29 * c-l-s module. Keep track of this number here.
30 */
31exports.ROOT_SPAN_STACK_OFFSET = useAsyncHooks ? 0 : 2;
32function createNamespace() {
33 return cls.createNamespace(TRACE_NAMESPACE);
34}
35exports.createNamespace = createNamespace;
36function destroyNamespace() {
37 cls.destroyNamespace(TRACE_NAMESPACE);
38}
39exports.destroyNamespace = destroyNamespace;
40function getNamespace() {
41 return cls.getNamespace(TRACE_NAMESPACE);
42}
43exports.getNamespace = getNamespace;
44exports.contextManager = createNamespace();
45//# sourceMappingURL=cls.js.map
\No newline at end of file