Skip to content

Commit

Permalink
fix baggage order
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jan 31, 2025
1 parent 7d403dd commit dff0b91
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/node/src/integrations/http/SentryHttpInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,16 +606,25 @@ function getAbsoluteUrl(origin: string, path: string = '/'): string {
function mergeBaggageHeaders(
existing: string | string[] | number | null | undefined | boolean,
baggage: string,
): string | undefined {
): string | string[] | number | null | undefined | boolean {
if (!existing) {
return baggage;
}

const existingBaggageEntries = parseBaggageHeader(existing);
const newBaggageEntries = parseBaggageHeader(baggage);

// Existing entries take precedence
const mergedBaggageEntries = { ...newBaggageEntries, ...existingBaggageEntries };
if (!newBaggageEntries) {
return existing;
}

// Existing entries take precedence, ensuring order remains stable for minimal changes
const mergedBaggageEntries = { ...existingBaggageEntries };
Object.entries(newBaggageEntries).forEach(([key, value]) => {
if (!mergedBaggageEntries[key]) {
mergedBaggageEntries[key] = value;
}
});

return objectToBaggageHeader(mergedBaggageEntries);
}

0 comments on commit dff0b91

Please sign in to comment.