Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(browser): Add integration test for changing transaction name in beforeSendTransaction #14495

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [Sentry.browserTracingIntegration()],
beforeSendTransaction: transactionEvent => {
const op = transactionEvent.contexts.trace.op;
if (op === 'pageload' || op === 'navigation') {
// use whatever logic you want to set the name
transactionEvent.transaction = 'customName';

transactionEvent.transaction_info.source = 'route';
transactionEvent.contexts.trace.data = {
...transactionEvent.contexts.trace.data,
[Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
};
}
return transactionEvent;
},
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';

import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/browser';
import { sentryTest } from '../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../utils/helpers';

sentryTest(
'allows modification of the transaction name and source but overwrites source to custom',
async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

const url = await getLocalTestUrl({ testDir: __dirname });

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(eventData.type).toBe('transaction');

// user-changed name
expect(eventData.transaction).toBe('customName');

// Despite the user setting the source to 'route', the SDK detects that the txn name was changed
// and therefore sets the transaction_info.source to 'custom'. This is not ideal but also not easily changeable.
// Given that Relay doesn't differentiate between 'source' and 'route', we'll keep this as-is for now.
expect(eventData.transaction_info?.source).toBe('custom');

// This stays the same but it has no effect on Relay.
expect(eventData.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('route');
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ import * as Sentry from '@sentry/browser';
window.Sentry = Sentry;
window._testBaseTimestamp = performance.timeOrigin / 1000;

const sentryFeatureFlagsIntegration = Sentry.featureFlagsIntegration({
featureFlags: {
'session-aggregates': true,
},
});

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1,
integrations: [sentryFeatureFlagsIntegration],
});

Sentry.getFlagsIntegration().addFlags({
'session-aggregates': true,
});

Sentry.addFlags({
'session-aggregates': true,
});
Loading