addBaggageHeader function
void
addBaggageHeader(
- SentryBaggageHeader baggage,
- Map<
String, dynamic> headers, { - SentryLogger? logger,
Implementation
void addBaggageHeader(
SentryBaggageHeader baggage,
Map<String, dynamic> headers, {
SentryLogger? logger,
}) {
final currentValue = headers[baggage.name] as String? ?? '';
final currentBaggage = SentryBaggage.fromHeader(
currentValue,
logger: logger,
);
final sentryBaggage = SentryBaggage.fromHeader(
baggage.value,
logger: logger,
);
// overwrite sentry's keys https://develop.sentry.dev/sdk/performance/dynamic-sampling-context/#baggage
final filteredBaggageHeader = Map.from(currentBaggage.keyValues);
filteredBaggageHeader.removeWhere((key, value) => key.startsWith('sentry-'));
final mergedBaggage = <String, String>{
...filteredBaggageHeader,
...sentryBaggage.keyValues,
};
final newBaggage = SentryBaggage(mergedBaggage, logger: logger);
headers[baggage.name] = newBaggage.toHeaderString();
}