Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Add dsn to span envelope header #12096

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ export function createSpanEnvelope(spans: SentrySpan[], client?: Client): SpanEn
// different segments in one envelope
const dsc = getDynamicSamplingContextFromSpan(spans[0]);

const dsn = client && client.getDsn();
const tunnel = client && client.getOptions().tunnel;

const headers: SpanEnvelope[0] = {
sent_at: new Date().toISOString(),
...(dscHasRequiredProps(dsc) && { trace: dsc }),
...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),
};

const beforeSendSpan = client && client.getOptions().beforeSendSpan;
Expand Down
26 changes: 26 additions & 0 deletions packages/core/test/lib/envelope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@ describe('createSpanEnvelope', () => {
});
});

it('adds `dsn` envelope header if tunnel is enabled', () => {
const options = getDefaultTestClientOptions({ dsn: 'https://username@domain/123', tunnel: 'http://tunnel' });
const client = new TestClient(options);

const spanEnvelope = createSpanEnvelope(
[new SentrySpan({ name: 'test', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom' } })],
client,
);

const spanEnvelopeHeaders = spanEnvelope[0];
expect(spanEnvelopeHeaders.dsn).toEqual('https://username@domain/123');
});

it('does not add `dsn` envelope header if tunnel is not enabled', () => {
const options = getDefaultTestClientOptions({ dsn: 'https://username@domain/123' });
const client = new TestClient(options);

const spanEnvelope = createSpanEnvelope(
[new SentrySpan({ name: 'test', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom' } })],
client,
);

const spanEnvelopeHeaders = spanEnvelope[0];
expect(spanEnvelopeHeaders.dsn).toBeUndefined();
});

it("doesn't add a `trace` envelope header if there's no public key", () => {
const options = getDefaultTestClientOptions({ tracesSampleRate: 1, dsn: 'https://domain/123' });
client = new TestClient(options);
Expand Down
Loading