1 | ;
|
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 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.PropagationAPI = void 0;
|
19 | const global_utils_1 = require("../internal/global-utils");
|
20 | const NoopTextMapPropagator_1 = require("../propagation/NoopTextMapPropagator");
|
21 | const TextMapPropagator_1 = require("../propagation/TextMapPropagator");
|
22 | const context_helpers_1 = require("../baggage/context-helpers");
|
23 | const utils_1 = require("../baggage/utils");
|
24 | const diag_1 = require("./diag");
|
25 | const API_NAME = 'propagation';
|
26 | const NOOP_TEXT_MAP_PROPAGATOR = new NoopTextMapPropagator_1.NoopTextMapPropagator();
|
27 | /**
|
28 | * Singleton object which represents the entry point to the OpenTelemetry Propagation API
|
29 | */
|
30 | class PropagationAPI {
|
31 | /** Empty private constructor prevents end users from constructing a new instance of the API */
|
32 | constructor() {
|
33 | this.createBaggage = utils_1.createBaggage;
|
34 | this.getBaggage = context_helpers_1.getBaggage;
|
35 | this.getActiveBaggage = context_helpers_1.getActiveBaggage;
|
36 | this.setBaggage = context_helpers_1.setBaggage;
|
37 | this.deleteBaggage = context_helpers_1.deleteBaggage;
|
38 | }
|
39 | /** Get the singleton instance of the Propagator API */
|
40 | static getInstance() {
|
41 | if (!this._instance) {
|
42 | this._instance = new PropagationAPI();
|
43 | }
|
44 | return this._instance;
|
45 | }
|
46 | /**
|
47 | * Set the current propagator.
|
48 | *
|
49 | * @returns true if the propagator was successfully registered, else false
|
50 | */
|
51 | setGlobalPropagator(propagator) {
|
52 | return (0, global_utils_1.registerGlobal)(API_NAME, propagator, diag_1.DiagAPI.instance());
|
53 | }
|
54 | /**
|
55 | * Inject context into a carrier to be propagated inter-process
|
56 | *
|
57 | * @param context Context carrying tracing data to inject
|
58 | * @param carrier carrier to inject context into
|
59 | * @param setter Function used to set values on the carrier
|
60 | */
|
61 | inject(context, carrier, setter = TextMapPropagator_1.defaultTextMapSetter) {
|
62 | return this._getGlobalPropagator().inject(context, carrier, setter);
|
63 | }
|
64 | /**
|
65 | * Extract context from a carrier
|
66 | *
|
67 | * @param context Context which the newly created context will inherit from
|
68 | * @param carrier Carrier to extract context from
|
69 | * @param getter Function used to extract keys from a carrier
|
70 | */
|
71 | extract(context, carrier, getter = TextMapPropagator_1.defaultTextMapGetter) {
|
72 | return this._getGlobalPropagator().extract(context, carrier, getter);
|
73 | }
|
74 | /**
|
75 | * Return a list of all fields which may be used by the propagator.
|
76 | */
|
77 | fields() {
|
78 | return this._getGlobalPropagator().fields();
|
79 | }
|
80 | /** Remove the global propagator */
|
81 | disable() {
|
82 | (0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
|
83 | }
|
84 | _getGlobalPropagator() {
|
85 | return (0, global_utils_1.getGlobal)(API_NAME) || NOOP_TEXT_MAP_PROPAGATOR;
|
86 | }
|
87 | }
|
88 | exports.PropagationAPI = PropagationAPI;
|
89 | //# sourceMappingURL=propagation.js.map |
\ | No newline at end of file |