Skip to content

Commit c06f455

Browse files
Only inject Session ID header if propagator=Datadog|W3C
1 parent 6007a26 commit c06f455

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

packages/core/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ export const getTracingHeadersFromAttributes = (
4848
if (tracingAttributes.tracingStrategy === 'DISCARD') {
4949
return headers;
5050
}
51+
52+
let hasDatadogOrW3CPropagator = false;
5153
tracingAttributes.propagatorTypes.forEach(propagator => {
5254
switch (propagator) {
5355
case PropagatorType.DATADOG: {
56+
hasDatadogOrW3CPropagator = true;
5457
headers.push(
5558
{
5659
header: ORIGIN_HEADER_KEY,
@@ -82,6 +85,7 @@ export const getTracingHeadersFromAttributes = (
8285
break;
8386
}
8487
case PropagatorType.TRACECONTEXT: {
88+
hasDatadogOrW3CPropagator = true;
8589
const isSampled =
8690
tracingAttributes.samplingPriorityHeader === '1';
8791
headers.push(
@@ -139,7 +143,7 @@ export const getTracingHeadersFromAttributes = (
139143
}
140144
});
141145

142-
if (tracingAttributes.rumSessionId) {
146+
if (hasDatadogOrW3CPropagator && tracingAttributes.rumSessionId) {
143147
headers.push({
144148
header: BAGGAGE_HEADER_KEY,
145149
value: `${DD_RUM_SESSION_ID_TAG}=${tracingAttributes.rumSessionId}`

packages/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,44 @@ describe('XHRProxy', () => {
840840
expect(xhr.requestHeaders[BAGGAGE_HEADER_KEY]).toBeUndefined();
841841
});
842842

843+
it('does not add rum session id to baggage headers when propagator type is not datadog or w3c', async () => {
844+
// GIVEN
845+
const method = 'GET';
846+
const url = 'https://example.com';
847+
xhrProxy.onTrackingStart({
848+
tracingSamplingRate: 100,
849+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
850+
{
851+
match: 'api.example.com',
852+
propagatorTypes: [
853+
PropagatorType.DATADOG,
854+
PropagatorType.TRACECONTEXT
855+
]
856+
},
857+
{
858+
match: 'example.com', // <-- no datadog or tracecontext here
859+
propagatorTypes: [
860+
PropagatorType.B3,
861+
PropagatorType.B3MULTI
862+
]
863+
}
864+
])
865+
});
866+
867+
setCachedSessionId('TEST-SESSION-ID');
868+
869+
// WHEN
870+
const xhr = new XMLHttpRequestMock();
871+
xhr.open(method, url);
872+
xhr.send();
873+
xhr.notifyResponseArrived();
874+
xhr.complete(200, 'ok');
875+
await flushPromises();
876+
877+
// THEN
878+
expect(xhr.requestHeaders[BAGGAGE_HEADER_KEY]).toBeUndefined();
879+
});
880+
843881
it('rum session id does not overwrite existing baggage headers', async () => {
844882
// GIVEN
845883
const method = 'GET';

0 commit comments

Comments
 (0)