Skip to content

Commit

Permalink
ref(core): Use sdkProcessingMetadata field for transaction sampling…
Browse files Browse the repository at this point in the history
… data (#4388)

In #4252, a new `sdkProcessingMetadata` field was added to the `Scope` and `Event` interfaces, to provide a place to put data which is needed for in-SDK event processing but shouldn't be sent to Sentry. This refactors one step in that processing... process... to use the new field, eliminating the need to pull the data out of `debug_meta` before the event is sent.
  • Loading branch information
lobsterkatie committed Jan 13, 2022
1 parent c5127a0 commit 8d64509
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 34 deletions.
7 changes: 1 addition & 6 deletions packages/core/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@ export function eventToSentryRequest(event: Event, api: APIDetails): SentryReque
const eventType = event.type || 'event';
const useEnvelope = eventType === 'transaction' || !!api.tunnel;

const { transactionSampling, ...metadata } = event.debug_meta || {};
const { transactionSampling } = event.sdkProcessingMetadata || {};
const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};
if (Object.keys(metadata).length === 0) {
delete event.debug_meta;
} else {
event.debug_meta = metadata;
}

// prevent this data from being sent to sentry
delete event.sdkProcessingMetadata;
Expand Down
29 changes: 3 additions & 26 deletions packages/core/test/lib/request.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DebugMeta, Event, SentryRequest } from '@sentry/types';
import { Event, SentryRequest } from '@sentry/types';

import { initAPIDetails } from '../../src/api';
import { eventToSentryRequest, sessionToSentryRequest } from '../../src/request';
Expand Down Expand Up @@ -42,11 +42,12 @@ describe('eventToSentryRequest', () => {
transaction: '/dogs/are/great/',
type: 'transaction',
user: { id: '1121', username: 'CharlieDog', ip_address: '11.21.20.12' },
sdkProcessingMetadata: {},
};
});

it('adds transaction sampling information to item header', () => {
event.debug_meta = { transactionSampling: { method: 'client_rate', rate: 0.1121 } };
event.sdkProcessingMetadata = { transactionSampling: { method: 'client_rate', rate: 0.1121 } };

const result = eventToSentryRequest(event, api);
const envelope = parseEnvelopeRequest(result);
Expand All @@ -58,30 +59,6 @@ describe('eventToSentryRequest', () => {
);
});

it('removes transaction sampling information (and only that) from debug_meta', () => {
event.debug_meta = {
transactionSampling: { method: 'client_sampler', rate: 0.1121 },
dog: 'Charlie',
} as DebugMeta;

const result = eventToSentryRequest(event, api);
const envelope = parseEnvelopeRequest(result);

expect('transactionSampling' in envelope.event.debug_meta).toBe(false);
expect('dog' in envelope.event.debug_meta).toBe(true);
});

it('removes debug_meta entirely if it ends up empty', () => {
event.debug_meta = {
transactionSampling: { method: 'client_rate', rate: 0.1121 },
} as DebugMeta;

const result = eventToSentryRequest(event, api);
const envelope = parseEnvelopeRequest(result);

expect('debug_meta' in envelope.event).toBe(false);
});

it('adds sdk info to envelope header', () => {
const result = eventToSentryRequest(event, api);
const envelope = parseEnvelopeRequest(result);
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
timestamp: this.endTimestamp,
transaction: this.name,
type: 'transaction',
debug_meta: this.metadata,
sdkProcessingMetadata: this.metadata,
};

const hasMeasurements = Object.keys(this._measurements).length > 0;
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/debugMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
**/
export interface DebugMeta {
images?: Array<DebugImage>;
transactionSampling?: { rate?: number; method?: string };
}

/**
Expand Down

0 comments on commit 8d64509

Please sign in to comment.