Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module.exports = [
import: createImport('init', 'ErrorBoundary', 'reactRouterV6BrowserTracingIntegration'),
ignore: ['react/jsx-runtime'],
gzip: true,
limit: '46 KB',
limit: '47 KB',
},
// Vue SDK (ESM)
{
Expand Down Expand Up @@ -241,14 +241,14 @@ module.exports = [
path: createCDNPath('bundle.min.js'),
gzip: false,
brotli: false,
limit: '83.5 KB',
limit: '84 KB',
},
{
name: 'CDN Bundle (incl. Tracing) - uncompressed',
path: createCDNPath('bundle.tracing.min.js'),
gzip: false,
brotli: false,
limit: '134 KB',
limit: '135 KB',
},
{
name: 'CDN Bundle (incl. Logs, Metrics) - uncompressed',
Expand All @@ -269,14 +269,14 @@ module.exports = [
path: createCDNPath('bundle.replay.logs.metrics.min.js'),
gzip: false,
brotli: false,
limit: '211 KB',
limit: '212 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay) - uncompressed',
path: createCDNPath('bundle.tracing.replay.min.js'),
gzip: false,
brotli: false,
limit: '251 KB',
limit: '252 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed',
Expand All @@ -290,7 +290,7 @@ module.exports = [
path: createCDNPath('bundle.tracing.replay.feedback.min.js'),
gzip: false,
brotli: false,
limit: '264 KB',
limit: '265 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [Sentry.spanStreamingIntegration(), Sentry.browserTracingIntegration()],
tracesSampleRate: 1.0,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from '@playwright/test';
import { sentryTest } from '../../../utils/fixtures';
import { getSpanOp, waitForStreamedSpans } from '../../../utils/spanUtils';
import { shouldSkipTracingTest, testingCdnBundle } from '../../../utils/helpers';

sentryTest('cultureContextIntegration captures locale, timezone, and calendar', async ({ getLocalTestUrl, page }) => {
sentryTest.skip(shouldSkipTracingTest() || testingCdnBundle());
const url = await getLocalTestUrl({ testDir: __dirname });

const spansPromise = waitForStreamedSpans(page, spans => spans.some(s => getSpanOp(s) === 'pageload'));

await page.goto(url);

const spans = await spansPromise;

const pageloadSpan = spans.find(s => getSpanOp(s) === 'pageload');

expect(pageloadSpan!.attributes?.['culture.locale']).toEqual({ type: 'string', value: expect.any(String) });
expect(pageloadSpan!.attributes?.['culture.timezone']).toEqual({ type: 'string', value: expect.any(String) });
expect(pageloadSpan!.attributes?.['culture.calendar']).toEqual({ type: 'string', value: expect.any(String) });
});
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ sentryTest(
},
{
attributes: {
'culture.calendar': {
type: 'string',
value: expect.any(String),
},
'culture.locale': {
type: 'string',
value: expect.any(String),
},
'culture.timezone': {
type: 'string',
value: expect.any(String),
},
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: {
type: 'string',
value: 'test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ sentryTest('captures streamed interaction span tree. @firefox', async ({ browser

expect(interactionSegmentSpan).toEqual({
attributes: {
'culture.calendar': {
type: 'string',
value: expect.any(String),
},
'culture.locale': {
type: 'string',
value: expect.any(String),
},
'culture.timezone': {
type: 'string',
value: expect.any(String),
},
[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]: {
type: 'string',
value: 'idleTimeout',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ sentryTest('starts a streamed navigation span on page navigation', async ({ getL

expect(navigationSpan).toEqual({
attributes: {
'culture.calendar': {
type: 'string',
value: expect.any(String),
},
'culture.locale': {
type: 'string',
value: expect.any(String),
},
'culture.timezone': {
type: 'string',
value: expect.any(String),
},
'network.connection.effective_type': {
type: 'string',
value: expect.any(String),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ sentryTest(

expect(pageloadSpan).toEqual({
attributes: {
'culture.calendar': {
type: 'string',
value: expect.any(String),
},
'culture.locale': {
type: 'string',
value: expect.any(String),
},
'culture.timezone': {
type: 'string',
value: expect.any(String),
},
// formerly known as 'effectiveConnectionType'
'network.connection.effective_type': {
type: 'string',
Expand Down
12 changes: 12 additions & 0 deletions packages/browser/src/integrations/culturecontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ const _cultureContextIntegration = (() => {
};
}
},
processSegmentSpan(span) {
const culture = getCultureContext();

if (culture) {
span.attributes = {
'culture.locale': culture.locale,
'culture.timezone': culture.timezone,
'culture.calendar': culture.calendar,
...span.attributes,
};
Comment thread
Lms24 marked this conversation as resolved.
}
},
};
}) satisfies IntegrationFn;

Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DEBUG_BUILD } from './debug-build';
import type { Event, EventHint } from './types-hoist/event';
import type { Integration, IntegrationFn } from './types-hoist/integration';
import type { CoreOptions } from './types-hoist/options';
import type { StreamedSpanJSON } from './types-hoist/span';
import { debug } from './utils/debug-logger';

export const installedIntegrations: string[] = [];
Expand Down Expand Up @@ -138,6 +139,15 @@ export function setupIntegration(client: Client, integration: Integration, integ
client.addEventProcessor(processor);
}

(['processSpan', 'processSegmentSpan'] as const).forEach(hook => {
const callback = integration[hook];
if (typeof callback === 'function') {
// The cast is needed because TS can't resolve overloads when the discriminant is a union type.
// Both overloads have the same callback signature so this is safe.
client.on(hook as 'processSpan', (span: StreamedSpanJSON) => callback.call(integration, span, client));
}
});

DEBUG_BUILD && debug.log(`Integration installed: ${integration.name}`);
}

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/integrations/requestdata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineIntegration } from '../integration';
import { hasSpanStreamingEnabled } from '../tracing/spans/hasSpanStreamingEnabled';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we are not emitting errors for unused imports during linting, should we change that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I brought this up a while ago. +1 for erroring on lint warnings all together tbh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes agreed, seems like warnings usually get ignored so mostly add noise

import type { Event } from '../types-hoist/event';
import type { IntegrationFn } from '../types-hoist/integration';
import type { RequestEventData } from '../types-hoist/request';
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/tracing/spans/captureSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ export function captureSpan(span: Span, client: Client): SerializedStreamedSpanW
if (spanJSON.is_segment) {
applyScopeToSegmentSpan(spanJSON, finalScopeData);
// Allow hook subscribers to mutate the segment span JSON
// This also invokes the `processSegmentSpan` hook of all integrations
client.emit('processSegmentSpan', spanJSON);
}

// Allow hook subscribers to mutate the span JSON
// This allows hook subscribers to mutate the span JSON
// This also invokes the `processSpan` hook of all integrations
client.emit('processSpan', spanJSON);

const { beforeSendSpan } = client.getOptions();
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/types-hoist/integration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Client } from '../client';
import type { Event, EventHint } from './event';
import type { StreamedSpanJSON } from './span';

/** Integration interface */
export interface Integration {
Expand Down Expand Up @@ -50,6 +51,20 @@ export interface Integration {
* This receives the client that the integration was installed for as third argument.
*/
processEvent?(event: Event, hint: EventHint, client: Client): Event | null | PromiseLike<Event | null>;

/**
* An optional hook that allows modifications to a span. This hook runs after the span is ended,
* during `captureSpan` and before the span is passed to users' `beforeSendSpan` callback.
* Use this hook to modify a span in-place.
*/
processSpan?(span: StreamedSpanJSON, client: Client): void;

/**
* An optional hook that allows modifications to a segment span. This hook runs after the segment span is ended,
* during `captureSpan` and before the segment span is passed to users' `beforeSendSpan` callback.
* Use this hook to modify a segment span in-place.
*/
processSegmentSpan?(span: StreamedSpanJSON, client: Client): void;
}

/**
Expand Down
Loading