Skip to content

Commit

Permalink
ref(tracing): Add propagations to tracing SDK (#5719)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AbhiPrasad committed Sep 13, 2022
1 parent 8f19db5 commit 60b394a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/tracing/src/browser/request.ts
Expand Up @@ -199,6 +199,7 @@ export function fetchCallback(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const options = (handlerData.args[1] = (handlerData.args[1] as { [key: string]: any }) || {});
options.headers = addTracingHeaders(request, activeTransaction.getBaggage(), span, options);
activeTransaction.metadata.propagations += 1;
}
}

Expand Down Expand Up @@ -304,6 +305,7 @@ export function xhrCallback(
BAGGAGE_HEADER_NAME,
mergeAndSerializeBaggage(activeTransaction.getBaggage(), headerBaggageString),
);
activeTransaction.metadata.propagations += 1;
} catch (_) {
// Error: InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
}
Expand Down
26 changes: 26 additions & 0 deletions packages/tracing/test/browser/request.test.ts
Expand Up @@ -193,6 +193,19 @@ describe('callbacks', () => {
expect(newSpan).toBeUndefined();
});

it('records outgoing propogations', () => {
const firstReqData = { ...fetchHandlerData };
const secondReqData = { ...fetchHandlerData };

expect(transaction.metadata.propagations).toBe(0);

fetchCallback(firstReqData, alwaysCreateSpan, {});
expect(transaction.metadata.propagations).toBe(1);

fetchCallback(secondReqData, alwaysCreateSpan, {});
expect(transaction.metadata.propagations).toBe(2);
});

it('adds sentry-trace header to fetch requests', () => {
// TODO
});
Expand Down Expand Up @@ -304,5 +317,18 @@ describe('callbacks', () => {

expect(newSpan).toBeUndefined();
});

it('records outgoing propogations', () => {
const firstReqData = { ...xhrHandlerData };
const secondReqData = { ...xhrHandlerData };

expect(transaction.metadata.propagations).toBe(0);

xhrCallback(firstReqData, alwaysCreateSpan, {});
expect(transaction.metadata.propagations).toBe(1);

xhrCallback(secondReqData, alwaysCreateSpan, {});
expect(transaction.metadata.propagations).toBe(2);
});
});
});

0 comments on commit 60b394a

Please sign in to comment.