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

feat(core): Add DSC to all outgoing envelopes #7820

Merged
merged 5 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,16 @@ export class Scope implements ScopeInterface {
// errors with transaction and it relies on that.
if (this._span) {
event.contexts = { trace: this._span.getTraceContext(), ...event.contexts };
const transactionName = this._span.transaction && this._span.transaction.name;
if (transactionName) {
event.tags = { transaction: transactionName, ...event.tags };
const transaction = this._span.transaction;
if (transaction) {
event.sdkProcessingMetadata = {
...event.sdkProcessingMetadata,
dynamicSamplingContext: transaction.getDynamicSamplingContext(),
};
const transactionName = transaction.name;
if (transactionName) {
event.tags = { transaction: transactionName, ...event.tags };
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions packages/core/test/lib/envelope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ const testDsn: DsnComponents = { protocol: 'https', projectId: 'abc', host: 'tes

describe('createEventEnvelope', () => {
describe('trace header', () => {
it("doesn't add trace header if event is not a transaction", () => {
const event: Event = {};
it('adds a trace header to error events', () => {
const event: Event = {
sdkProcessingMetadata: {
dynamicSamplingContext: { trace_id: '1234', public_key: 'pubKey123' },
},
};
const envelopeHeaders = createEventEnvelope(event, testDsn)[0];

expect(envelopeHeaders).toBeDefined();
expect(envelopeHeaders.trace).toBeUndefined();
expect(envelopeHeaders.trace).toBeDefined();
});

const testTable: Array<[string, Event, DynamicSamplingContext]> = [
Expand Down
8 changes: 3 additions & 5 deletions packages/utils/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,13 @@ export function createEventEnvelopeHeaders(
dsn: DsnComponents,
): EventEnvelopeHeaders {
const dynamicSamplingContext = event.sdkProcessingMetadata && event.sdkProcessingMetadata.dynamicSamplingContext;

return {
event_id: event.event_id as string,
sent_at: new Date().toISOString(),
...(sdkInfo && { sdk: sdkInfo }),
...(!!tunnel && { dsn: dsnToString(dsn) }),
...(event.type === 'transaction' &&
dynamicSamplingContext && {
trace: dropUndefinedKeys({ ...dynamicSamplingContext }),
}),
...(dynamicSamplingContext && {
trace: dropUndefinedKeys({ ...dynamicSamplingContext }),
}),
};
}