1 | ;
|
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 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const semver = require("semver");
|
19 | const useAsyncHooks = semver.satisfies(process.version, '>=8'); //&&
|
20 | // !!process.env.GCLOUD_TRACE_NEW_CONTEXT;
|
21 | const cls = useAsyncHooks
|
22 | ? require('./cls-ah')
|
23 | : require('continuation-local-storage');
|
24 | const 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 | */
|
31 | exports.ROOT_SPAN_STACK_OFFSET = useAsyncHooks ? 0 : 2;
|
32 | function createNamespace() {
|
33 | return cls.createNamespace(TRACE_NAMESPACE);
|
34 | }
|
35 | exports.createNamespace = createNamespace;
|
36 | function destroyNamespace() {
|
37 | cls.destroyNamespace(TRACE_NAMESPACE);
|
38 | }
|
39 | exports.destroyNamespace = destroyNamespace;
|
40 | function getNamespace() {
|
41 | return cls.getNamespace(TRACE_NAMESPACE);
|
42 | }
|
43 | exports.getNamespace = getNamespace;
|
44 | exports.contextManager = createNamespace();
|
45 | //# sourceMappingURL=cls.js.map |
\ | No newline at end of file |