UNPKG

1.89 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.baggageEntryMetadataFromString = exports.createBaggage = void 0;
19var diag_1 = require("../api/diag");
20var baggage_impl_1 = require("./internal/baggage-impl");
21var symbol_1 = require("./internal/symbol");
22var diag = diag_1.DiagAPI.instance();
23/**
24 * Create a new Baggage with optional entries
25 *
26 * @param entries An array of baggage entries the new baggage should contain
27 */
28function createBaggage(entries) {
29 if (entries === void 0) { entries = {}; }
30 return new baggage_impl_1.BaggageImpl(new Map(Object.entries(entries)));
31}
32exports.createBaggage = createBaggage;
33/**
34 * Create a serializable BaggageEntryMetadata object from a string.
35 *
36 * @param str string metadata. Format is currently not defined by the spec and has no special meaning.
37 *
38 */
39function baggageEntryMetadataFromString(str) {
40 if (typeof str !== 'string') {
41 diag.error("Cannot create baggage metadata from unknown type: " + typeof str);
42 str = '';
43 }
44 return {
45 __TYPE__: symbol_1.baggageEntryMetadataSymbol,
46 toString: function () {
47 return str;
48 },
49 };
50}
51exports.baggageEntryMetadataFromString = baggageEntryMetadataFromString;
52//# sourceMappingURL=utils.js.map
\No newline at end of file