diff --git a/packages/integration-tests/suites/tracing/browsertracing/navigation/test.ts b/packages/integration-tests/suites/tracing/browsertracing/navigation/test.ts index 57c035a96b85..622ecdd55173 100644 --- a/packages/integration-tests/suites/tracing/browsertracing/navigation/test.ts +++ b/packages/integration-tests/suites/tracing/browsertracing/navigation/test.ts @@ -13,6 +13,8 @@ sentryTest('should create a navigation transaction on page navigation', async ({ expect(pageloadRequest.contexts?.trace.op).toBe('pageload'); expect(navigationRequest.contexts?.trace.op).toBe('navigation'); + expect(navigationRequest.transaction_info?.source).toEqual('url'); + const pageloadTraceId = pageloadRequest.contexts?.trace.trace_id; const navigationTraceId = navigationRequest.contexts?.trace.trace_id; diff --git a/packages/integration-tests/suites/tracing/browsertracing/pageload/test.ts b/packages/integration-tests/suites/tracing/browsertracing/pageload/test.ts index bb8707ff51f8..6c5877c62e57 100644 --- a/packages/integration-tests/suites/tracing/browsertracing/pageload/test.ts +++ b/packages/integration-tests/suites/tracing/browsertracing/pageload/test.ts @@ -11,4 +11,5 @@ sentryTest('should create a pageload transaction', async ({ getLocalTestPath, pa expect(eventData.contexts?.trace?.op).toBe('pageload'); expect(eventData.spans?.length).toBeGreaterThan(0); + expect(eventData.transaction_info?.source).toEqual('url'); }); diff --git a/packages/tracing/src/browser/browsertracing.ts b/packages/tracing/src/browser/browsertracing.ts index 75e45b35e3da..ee927cf8a779 100644 --- a/packages/tracing/src/browser/browsertracing.ts +++ b/packages/tracing/src/browser/browsertracing.ts @@ -208,6 +208,12 @@ export class BrowserTracing implements Integration { const expandedContext = { ...context, ...parentContextFromHeader, + ...(parentContextFromHeader && { + metadata: { + ...context.metadata, + ...parentContextFromHeader.metadata, + }, + }), trimEnd: true, }; const modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate(expandedContext) : expandedContext; diff --git a/packages/tracing/src/browser/router.ts b/packages/tracing/src/browser/router.ts index 20add62319fd..b66037f38512 100644 --- a/packages/tracing/src/browser/router.ts +++ b/packages/tracing/src/browser/router.ts @@ -20,7 +20,11 @@ export function instrumentRoutingWithDefaults( let activeTransaction: T | undefined; if (startTransactionOnPageLoad) { - activeTransaction = customStartTransaction({ name: global.location.pathname, op: 'pageload' }); + activeTransaction = customStartTransaction({ + name: global.location.pathname, + op: 'pageload', + metadata: { source: 'url' }, + }); } if (startTransactionOnLocationChange) { @@ -46,7 +50,11 @@ export function instrumentRoutingWithDefaults( // If there's an open transaction on the scope, we need to finish it before creating an new one. activeTransaction.finish(); } - activeTransaction = customStartTransaction({ name: global.location.pathname, op: 'navigation' }); + activeTransaction = customStartTransaction({ + name: global.location.pathname, + op: 'navigation', + metadata: { source: 'url' }, + }); } }); } diff --git a/packages/tracing/test/browser/router.test.ts b/packages/tracing/test/browser/router.test.ts index 9d1ae86f4e01..f0e3fec29084 100644 --- a/packages/tracing/test/browser/router.test.ts +++ b/packages/tracing/test/browser/router.test.ts @@ -42,7 +42,11 @@ describe('instrumentRoutingWithDefaults', () => { it('starts a pageload transaction', () => { instrumentRoutingWithDefaults(customStartTransaction); expect(customStartTransaction).toHaveBeenCalledTimes(1); - expect(customStartTransaction).toHaveBeenLastCalledWith({ name: 'blank', op: 'pageload' }); + expect(customStartTransaction).toHaveBeenLastCalledWith({ + name: 'blank', + op: 'pageload', + metadata: { source: 'url' }, + }); }); it('does not start a pageload transaction if startTransactionOnPageLoad is false', () => { @@ -58,7 +62,11 @@ describe('instrumentRoutingWithDefaults', () => { it('it is not created automatically', () => { instrumentRoutingWithDefaults(customStartTransaction); - expect(customStartTransaction).not.toHaveBeenLastCalledWith({ name: 'blank', op: 'navigation' }); + expect(customStartTransaction).not.toHaveBeenLastCalledWith({ + name: 'blank', + op: 'navigation', + metadata: { source: 'url' }, + }); }); it('is created on location change', () => { @@ -67,7 +75,11 @@ describe('instrumentRoutingWithDefaults', () => { expect(addInstrumentationHandlerType).toBe('history'); expect(customStartTransaction).toHaveBeenCalledTimes(2); - expect(customStartTransaction).toHaveBeenLastCalledWith({ name: 'blank', op: 'navigation' }); + expect(customStartTransaction).toHaveBeenLastCalledWith({ + name: 'blank', + op: 'navigation', + metadata: { source: 'url' }, + }); }); it('is not created if startTransactionOnLocationChange is false', () => {