MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / parseBaggageHeader

Function parseBaggageHeader

packages/core/src/utils/baggage.ts:86–105  ·  view source on GitHub ↗
(
  baggageHeader: string | string[] | number | null | undefined | boolean,
)

Source from the content-addressed store, hash-verified

84 * Take a baggage header and parse it into an object.
85 */
86export function parseBaggageHeader(
87 baggageHeader: string | string[] | number | null | undefined | boolean,
88): Record<string, string> | undefined {
89 if (!baggageHeader || (!isString(baggageHeader) && !Array.isArray(baggageHeader))) {
90 return undefined;
91 }
92
93 if (Array.isArray(baggageHeader)) {
94 // Combine all baggage headers into one object containing the baggage values so we can later read the Sentry-DSC-values from it
95 return baggageHeader.reduce<Record<string, string>>((acc, curr) => {
96 const currBaggageObject = baggageHeaderToObject(curr);
97 Object.entries(currBaggageObject).forEach(([key, value]) => {
98 acc[key] = value;
99 });
100 return acc;
101 }, {});
102 }
103
104 return baggageHeaderToObject(baggageHeader);
105}
106
107/**
108 * Will parse a baggage header, which is a simple key-value map, into a flat object.

Callers 15

baggage.test.tsFile · 0.90
injectMethod · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
test.tsFile · 0.90

Calls 4

isStringFunction · 0.90
baggageHeaderToObjectFunction · 0.85
forEachMethod · 0.65
entriesMethod · 0.65

Tested by

no test coverage detected