Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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) });
});
13 changes: 13 additions & 0 deletions packages/browser/src/integrations/culturecontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ const _cultureContextIntegration = (() => {
};
}
},
processSegmentSpan(span) {
const culture = getCultureContext();

if (culture) {
span.attributes = {
'culture.locale': culture.locale,
'culture.timezone': culture.timezone,
'culture.calendar': culture.calendar,
xxxDeleteMe: undefined,
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
...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 @@ -138,6 +138,16 @@ export function setupIntegration(client: Client, integration: Integration, integ
client.addEventProcessor(processor);
}

if (typeof integration.processSpan === 'function') {
const callback = integration.processSpan.bind(integration) as typeof integration.processSpan;
client.on('processSpan', span => callback(span, client));
}

if (typeof integration.processSegmentSpan === 'function') {
const callback = integration.processSegmentSpan.bind(integration) as typeof integration.processSegmentSpan;
client.on('processSegmentSpan', span => callback(span, client));
}

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

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 { StreamedSpanJSON } from './span';

Check failure on line 3 in packages/core/src/types-hoist/integration.ts

View workflow job for this annotation

GitHub Actions / Lint

typescript-eslint(consistent-type-imports)

All imports in the declaration are only used as types. Use `import type`.

/** Integration interface */
export interface Integration {
Expand Down Expand Up @@ -50,6 +51,20 @@
* 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