Skip to content

Commit 6fb4c0d

Browse files
authored
ref(tracing): Simplify sample_rate serialization for DSC (#5475)
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.
1 parent e849076 commit 6fb4c0d

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

packages/tracing/src/transaction.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ export class Transaction extends SpanClass implements TransactionInterface {
245245
const { environment, release } = client.getOptions() || {};
246246
const { publicKey: public_key } = client.getDsn() || {};
247247

248-
const rate = this.metadata && this.metadata.transactionSampling && this.metadata.transactionSampling.rate;
249248
const sample_rate =
250-
rate !== undefined
251-
? rate.toLocaleString('fullwide', { useGrouping: false, maximumFractionDigits: 16 })
252-
: undefined;
249+
this.metadata &&
250+
this.metadata.transactionSampling &&
251+
this.metadata.transactionSampling.rate &&
252+
this.metadata.transactionSampling.rate.toString();
253253

254254
const scope = hub.getScope();
255255
const { segment: user_segment } = (scope && scope.getUser()) || {};

packages/tracing/test/span.test.ts

-24
Original file line numberDiff line numberDiff line change
@@ -449,30 +449,6 @@ describe('Span', () => {
449449
expect(baggage && getThirdPartyBaggage(baggage)).toStrictEqual('');
450450
});
451451

452-
test('exponential sample rate notation is converted to decimal notation', () => {
453-
const transaction = new Transaction(
454-
{
455-
name: 'tx',
456-
metadata: {
457-
transactionSampling: { rate: 1.45e-14, method: 'client_rate' },
458-
},
459-
},
460-
hub,
461-
);
462-
463-
const baggage = transaction.getBaggage();
464-
465-
expect(baggage && isSentryBaggageEmpty(baggage)).toBe(false);
466-
expect(baggage && getSentryBaggageItems(baggage)).toStrictEqual({
467-
release: '1.0.1',
468-
environment: 'production',
469-
// transaction: 'tx',
470-
sample_rate: '0.0000000000000145',
471-
trace_id: expect.any(String),
472-
});
473-
expect(baggage && getThirdPartyBaggage(baggage)).toStrictEqual('');
474-
});
475-
476452
describe('Including transaction name in DSC', () => {
477453
test.each([
478454
['is not included if transaction source is not set', undefined],

0 commit comments

Comments
 (0)