Skip to content

Commit

Permalink
ref(tracing): Simplify sample_rate serialization for DSC (#5475)
Browse files Browse the repository at this point in the history
Changes our formatting logic of the `sample_rate` value when the dynamic sampling context (DSC) is populated. Instead of using `Number.toLocaleString` with a bunch of options (which theoretically is supported by all browsers; but it turns out that IE11 doesn't support the `fullwide` locale we use), we now simply convert the number `toString` to do the job. Given that Relay now supports parsing the sample_rate from JSON format, we can drop our previous formatting logic. 

Deleted a test that's IMO no longer necessary, covering the conversion of exponential to decimal notation.
  • Loading branch information
Lms24 authored Jul 28, 2022
1 parent e849076 commit 6fb4c0d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
8 changes: 4 additions & 4 deletions packages/tracing/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ export class Transaction extends SpanClass implements TransactionInterface {
const { environment, release } = client.getOptions() || {};
const { publicKey: public_key } = client.getDsn() || {};

const rate = this.metadata && this.metadata.transactionSampling && this.metadata.transactionSampling.rate;
const sample_rate =
rate !== undefined
? rate.toLocaleString('fullwide', { useGrouping: false, maximumFractionDigits: 16 })
: undefined;
this.metadata &&
this.metadata.transactionSampling &&
this.metadata.transactionSampling.rate &&
this.metadata.transactionSampling.rate.toString();

const scope = hub.getScope();
const { segment: user_segment } = (scope && scope.getUser()) || {};
Expand Down
24 changes: 0 additions & 24 deletions packages/tracing/test/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,30 +449,6 @@ describe('Span', () => {
expect(baggage && getThirdPartyBaggage(baggage)).toStrictEqual('');
});

test('exponential sample rate notation is converted to decimal notation', () => {
const transaction = new Transaction(
{
name: 'tx',
metadata: {
transactionSampling: { rate: 1.45e-14, method: 'client_rate' },
},
},
hub,
);

const baggage = transaction.getBaggage();

expect(baggage && isSentryBaggageEmpty(baggage)).toBe(false);
expect(baggage && getSentryBaggageItems(baggage)).toStrictEqual({
release: '1.0.1',
environment: 'production',
// transaction: 'tx',
sample_rate: '0.0000000000000145',
trace_id: expect.any(String),
});
expect(baggage && getThirdPartyBaggage(baggage)).toStrictEqual('');
});

describe('Including transaction name in DSC', () => {
test.each([
['is not included if transaction source is not set', undefined],
Expand Down

0 comments on commit 6fb4c0d

Please sign in to comment.