UNPKG

@sentry/browser

Version:
76 lines (65 loc) 1.73 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const browser = require('@sentry/core/browser'); const helpers = require('../helpers.js'); 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) { browser.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 = browser.defineIntegration(_cultureContextIntegration); /** * Returns the culture context from the browser's Intl API. */ function getCultureContext() { try { const intl = (helpers.WINDOW ).Intl; if (!intl) { return undefined; } const options = intl.DateTimeFormat().resolvedOptions(); return { locale: options.locale, timezone: options.timeZone, calendar: options.calendar, }; } catch { // Ignore errors return undefined; } } exports.cultureContextIntegration = cultureContextIntegration; //# sourceMappingURL=culturecontext.js.map