@sentry/nextjs
Version:
Official Sentry SDK for Next.js
30 lines (23 loc) • 750 B
JavaScript
import { winterCGHeadersToDict, httpHeadersToSpanAttributes, getClient } from '@sentry/core';
/**
* Extracts HTTP request headers as span attributes and optionally applies them to a span.
*/
function addHeadersAsAttributes(
headers,
span,
) {
if (!headers) {
return {};
}
const headersDict =
headers instanceof Headers || (typeof headers === 'object' && 'get' in headers)
? winterCGHeadersToDict(headers )
: headers;
const headerAttributes = httpHeadersToSpanAttributes(headersDict, getClient()?.getOptions().sendDefaultPii ?? false);
if (span) {
span.setAttributes(headerAttributes);
}
return headerAttributes;
}
export { addHeadersAsAttributes };
//# sourceMappingURL=addHeadersAsAttributes.js.map