UNPKG

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