UNPKG

@sentry/browser

Version:
63 lines (62 loc) • 1.58 kB
import { WINDOW } from "../helpers.js"; import { defineIntegration, safeSetSpanJSONAttributes } from "@sentry/core"; import { CULTURE_CALENDAR, CULTURE_LOCALE, CULTURE_TIMEZONE } from "@sentry/conventions/attributes"; // src/integrations/culturecontext.ts const INTEGRATION_NAME = "CultureContext"; const _cultureContextIntegration = (() => { return { name: INTEGRATION_NAME, preprocessEvent(event) { const culture = getCultureContext(); if (culture) event.contexts = { ...event.contexts, culture: { ...culture, ...event.contexts?.culture } }; }, processSegmentSpan(span) { const culture = getCultureContext(); if (culture) safeSetSpanJSONAttributes(span, { [CULTURE_LOCALE]: culture.locale, [CULTURE_TIMEZONE]: culture.timezone, [CULTURE_CALENDAR]: culture.calendar }); } }; }); /** * Captures culture context from the browser. * * Enabled by default. * * @example * ```js * import * as Sentry from '@sentry/browser'; * * Sentry.init({ * integrations: [Sentry.cultureContextIntegration()], * }); * ``` */ const cultureContextIntegration = defineIntegration(_cultureContextIntegration); /** * Returns the culture context from the browser's Intl API. */ function getCultureContext() { try { const intl = WINDOW.Intl; if (!intl) return; const options = intl.DateTimeFormat().resolvedOptions(); return { locale: options.locale, timezone: options.timeZone, calendar: options.calendar }; } catch { return; } } export { cultureContextIntegration }; //# sourceMappingURL=culturecontext.js.map