Skip to content

Commit 60b394a

Browse files
authored
ref(tracing): Add propagations to tracing SDK (#5719)
This PR updates the propagations metadata field in the tracing SDK for `BrowserTracing`. It does this by adding a propagations incrementor to the fetch and XHR instrumentation.
1 parent 8f19db5 commit 60b394a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packages/tracing/src/browser/request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export function fetchCallback(
199199
// eslint-disable-next-line @typescript-eslint/no-explicit-any
200200
const options = (handlerData.args[1] = (handlerData.args[1] as { [key: string]: any }) || {});
201201
options.headers = addTracingHeaders(request, activeTransaction.getBaggage(), span, options);
202+
activeTransaction.metadata.propagations += 1;
202203
}
203204
}
204205

@@ -304,6 +305,7 @@ export function xhrCallback(
304305
BAGGAGE_HEADER_NAME,
305306
mergeAndSerializeBaggage(activeTransaction.getBaggage(), headerBaggageString),
306307
);
308+
activeTransaction.metadata.propagations += 1;
307309
} catch (_) {
308310
// Error: InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
309311
}

packages/tracing/test/browser/request.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ describe('callbacks', () => {
193193
expect(newSpan).toBeUndefined();
194194
});
195195

196+
it('records outgoing propogations', () => {
197+
const firstReqData = { ...fetchHandlerData };
198+
const secondReqData = { ...fetchHandlerData };
199+
200+
expect(transaction.metadata.propagations).toBe(0);
201+
202+
fetchCallback(firstReqData, alwaysCreateSpan, {});
203+
expect(transaction.metadata.propagations).toBe(1);
204+
205+
fetchCallback(secondReqData, alwaysCreateSpan, {});
206+
expect(transaction.metadata.propagations).toBe(2);
207+
});
208+
196209
it('adds sentry-trace header to fetch requests', () => {
197210
// TODO
198211
});
@@ -304,5 +317,18 @@ describe('callbacks', () => {
304317

305318
expect(newSpan).toBeUndefined();
306319
});
320+
321+
it('records outgoing propogations', () => {
322+
const firstReqData = { ...xhrHandlerData };
323+
const secondReqData = { ...xhrHandlerData };
324+
325+
expect(transaction.metadata.propagations).toBe(0);
326+
327+
xhrCallback(firstReqData, alwaysCreateSpan, {});
328+
expect(transaction.metadata.propagations).toBe(1);
329+
330+
xhrCallback(secondReqData, alwaysCreateSpan, {});
331+
expect(transaction.metadata.propagations).toBe(2);
332+
});
307333
});
308334
});

0 commit comments

Comments
 (0)