utils.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright The OpenTelemetry Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { DiagAPI } from '../api/diag';
  17. import { BaggageImpl } from './internal/baggage-impl';
  18. import { baggageEntryMetadataSymbol } from './internal/symbol';
  19. var diag = DiagAPI.instance();
  20. /**
  21. * Create a new Baggage with optional entries
  22. *
  23. * @param entries An array of baggage entries the new baggage should contain
  24. */
  25. export function createBaggage(entries) {
  26. if (entries === void 0) { entries = {}; }
  27. return new BaggageImpl(new Map(Object.entries(entries)));
  28. }
  29. /**
  30. * Create a serializable BaggageEntryMetadata object from a string.
  31. *
  32. * @param str string metadata. Format is currently not defined by the spec and has no special meaning.
  33. *
  34. */
  35. export function baggageEntryMetadataFromString(str) {
  36. if (typeof str !== 'string') {
  37. diag.error("Cannot create baggage metadata from unknown type: " + typeof str);
  38. str = '';
  39. }
  40. return {
  41. __TYPE__: baggageEntryMetadataSymbol,
  42. toString: function () {
  43. return str;
  44. },
  45. };
  46. }
  47. //# sourceMappingURL=utils.js.map