Skip to content

Commit a3cb664

Browse files
authored
feat(browser): Include culture context with events (#19148)
This PR includes the `culture` context containing the `locale`, `timeZone` and `calendar` information as outlined by the [Contexts interface doc](https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/#culture-context). I had this lying in my stash since the last Triage, just got some time to tidy it up and PR it. closes #18801
1 parent 3580d70 commit a3cb664

File tree

19 files changed

+175
-14
lines changed

19 files changed

+175
-14
lines changed

.size-limit.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = [
88
path: 'packages/browser/build/npm/esm/prod/index.js',
99
import: createImport('init'),
1010
gzip: true,
11-
limit: '25.5 KB',
11+
limit: '26 KB',
1212
},
1313
{
1414
name: '@sentry/browser - with treeshaking flags',
@@ -148,7 +148,7 @@ module.exports = [
148148
import: createImport('init', 'ErrorBoundary', 'reactRouterV6BrowserTracingIntegration'),
149149
ignore: ['react/jsx-runtime'],
150150
gzip: true,
151-
limit: '44.6 KB',
151+
limit: '45 KB',
152152
},
153153
// Vue SDK (ESM)
154154
{
@@ -163,22 +163,22 @@ module.exports = [
163163
path: 'packages/vue/build/esm/index.js',
164164
import: createImport('init', 'browserTracingIntegration'),
165165
gzip: true,
166-
limit: '44.1 KB',
166+
limit: '45 KB',
167167
},
168168
// Svelte SDK (ESM)
169169
{
170170
name: '@sentry/svelte',
171171
path: 'packages/svelte/build/esm/index.js',
172172
import: createImport('init'),
173173
gzip: true,
174-
limit: '25.5 KB',
174+
limit: '26 KB',
175175
},
176176
// Browser CDN bundles
177177
{
178178
name: 'CDN Bundle',
179179
path: createCDNPath('bundle.min.js'),
180180
gzip: true,
181-
limit: '28 KB',
181+
limit: '29 KB',
182182
},
183183
{
184184
name: 'CDN Bundle (incl. Tracing)',
@@ -234,7 +234,7 @@ module.exports = [
234234
path: createCDNPath('bundle.min.js'),
235235
gzip: false,
236236
brotli: false,
237-
limit: '82 KB',
237+
limit: '83 KB',
238238
},
239239
{
240240
name: 'CDN Bundle (incl. Tracing) - uncompressed',

dev-packages/browser-integration-tests/suites/feedback/attachTo/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ sentryTest('should capture feedback with custom button', async ({ getLocalTestUr
3939
type: 'feedback',
4040
breadcrumbs: expect.any(Array),
4141
contexts: {
42+
culture: {
43+
locale: expect.any(String),
44+
timezone: expect.any(String),
45+
calendar: expect.any(String),
46+
},
4247
feedback: {
4348
contact_email: 'janedoe@example.org',
4449
message: 'my example feedback',

dev-packages/browser-integration-tests/suites/feedback/captureFeedback/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
3737
type: 'feedback',
3838
breadcrumbs: expect.any(Array),
3939
contexts: {
40+
culture: {
41+
locale: expect.any(String),
42+
timezone: expect.any(String),
43+
calendar: expect.any(String),
44+
},
4045
feedback: {
4146
contact_email: 'janedoe@example.org',
4247
message: 'my example feedback',

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/hasSampling/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ sentryTest('should capture feedback', async ({ forceFlushReplay, getLocalTestUrl
7272
type: 'feedback',
7373
breadcrumbs: expect.any(Array),
7474
contexts: {
75+
culture: {
76+
locale: expect.any(String),
77+
timezone: expect.any(String),
78+
calendar: expect.any(String),
79+
},
7580
feedback: {
7681
contact_email: 'janedoe@example.org',
7782
message: 'my example feedback',

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
3737
type: 'feedback',
3838
breadcrumbs: expect.any(Array),
3939
contexts: {
40+
culture: {
41+
locale: expect.any(String),
42+
timezone: expect.any(String),
43+
calendar: expect.any(String),
44+
},
4045
feedback: {
4146
contact_email: 'janedoe@example.org',
4247
message: 'my example feedback',
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
const integrations = Sentry.getDefaultIntegrations({}).filter(
6+
defaultIntegration => defaultIntegration.name === 'CultureContext',
7+
);
8+
9+
const client = new Sentry.BrowserClient({
10+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
11+
transport: Sentry.makeFetchTransport,
12+
stackParser: Sentry.defaultStackParser,
13+
integrations: integrations,
14+
});
15+
16+
const scope = new Sentry.Scope();
17+
scope.setClient(client);
18+
client.init();
19+
20+
window._sentryScope = scope;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window._sentryScope.captureException(new Error('test error'));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/core';
3+
import { sentryTest } from '../../../utils/fixtures';
4+
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
5+
6+
sentryTest('cultureContextIntegration captures locale, timezone, and calendar', async ({ getLocalTestUrl, page }) => {
7+
const url = await getLocalTestUrl({ testDir: __dirname });
8+
9+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
10+
11+
expect(eventData.exception?.values).toHaveLength(1);
12+
13+
expect(eventData.contexts?.culture).toEqual({
14+
locale: expect.any(String),
15+
timezone: expect.any(String),
16+
calendar: expect.any(String),
17+
});
18+
});

dev-packages/browser-integration-tests/suites/public-api/debug/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ sentryTest('logs debug messages correctly', async ({ getLocalTestUrl, page }) =>
3333
'Sentry Logger [log]: Integration installed: LinkedErrors',
3434
'Sentry Logger [log]: Integration installed: Dedupe',
3535
'Sentry Logger [log]: Integration installed: HttpContext',
36+
'Sentry Logger [log]: Integration installed: CultureContext',
3637
'Sentry Logger [warn]: Discarded session because of missing or non-string release',
3738
'Sentry Logger [log]: Integration installed: BrowserSession',
3839
'test log',

dev-packages/browser-integration-tests/suites/public-api/startSpan/standalone-mixed-transaction/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ sentryTest(
8383
});
8484

8585
expect(transactionEnvelopeItem).toEqual({
86-
contexts: {
86+
contexts: expect.objectContaining({
8787
trace: {
8888
data: {
8989
'sentry.origin': 'manual',
@@ -94,7 +94,7 @@ sentryTest(
9494
span_id: parentSpanId,
9595
trace_id: traceId,
9696
},
97-
},
97+
}),
9898
environment: 'production',
9999
event_id: expect.any(String),
100100
platform: 'javascript',

0 commit comments

Comments
 (0)