Skip to content

Commit 56570b3

Browse files
authored
fix(core): Add dsn to span envelope header (#12096)
This was forgotten/got lost while we migrated this from v7 to v8. Now, adding the dsn again when the tunnel is enabled. Fixes #12094
1 parent 8fbff59 commit 56570b3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/core/src/envelope.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ export function createSpanEnvelope(spans: SentrySpan[], client?: Client): SpanEn
110110
// different segments in one envelope
111111
const dsc = getDynamicSamplingContextFromSpan(spans[0]);
112112

113+
const dsn = client && client.getDsn();
114+
const tunnel = client && client.getOptions().tunnel;
115+
113116
const headers: SpanEnvelope[0] = {
114117
sent_at: new Date().toISOString(),
115118
...(dscHasRequiredProps(dsc) && { trace: dsc }),
119+
...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),
116120
};
117121

118122
const beforeSendSpan = client && client.getOptions().beforeSendSpan;

packages/core/test/lib/envelope.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ describe('createSpanEnvelope', () => {
144144
});
145145
});
146146

147+
it('adds `dsn` envelope header if tunnel is enabled', () => {
148+
const options = getDefaultTestClientOptions({ dsn: 'https://username@domain/123', tunnel: 'http://tunnel' });
149+
const client = new TestClient(options);
150+
151+
const spanEnvelope = createSpanEnvelope(
152+
[new SentrySpan({ name: 'test', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom' } })],
153+
client,
154+
);
155+
156+
const spanEnvelopeHeaders = spanEnvelope[0];
157+
expect(spanEnvelopeHeaders.dsn).toEqual('https://username@domain/123');
158+
});
159+
160+
it('does not add `dsn` envelope header if tunnel is not enabled', () => {
161+
const options = getDefaultTestClientOptions({ dsn: 'https://username@domain/123' });
162+
const client = new TestClient(options);
163+
164+
const spanEnvelope = createSpanEnvelope(
165+
[new SentrySpan({ name: 'test', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom' } })],
166+
client,
167+
);
168+
169+
const spanEnvelopeHeaders = spanEnvelope[0];
170+
expect(spanEnvelopeHeaders.dsn).toBeUndefined();
171+
});
172+
147173
it("doesn't add a `trace` envelope header if there's no public key", () => {
148174
const options = getDefaultTestClientOptions({ tracesSampleRate: 1, dsn: 'https://domain/123' });
149175
client = new TestClient(options);

0 commit comments

Comments
 (0)