Skip to content

Commit ca2bc55

Browse files
committed
update
1 parent 04c7e0b commit ca2bc55

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

dart/lib/src/sentry_trace_context_header.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class SentryTraceContextHeader {
105105
baggage.setSampleRate(sampleRate!);
106106
}
107107
if (sampleRand != null) {
108-
baggage.setSampleRate(sampleRand!);
108+
baggage.setSampleRand(sampleRand!);
109109
}
110110
if (sampled != null) {
111111
baggage.setSampled(sampled!);
@@ -118,6 +118,7 @@ class SentryTraceContextHeader {
118118

119119
factory SentryTraceContextHeader.fromBaggage(SentryBaggage baggage) {
120120
return SentryTraceContextHeader(
121+
// TODO: implement and use proper get methods here
121122
SentryId.fromId(baggage.get('sentry-trace_id').toString()),
122123
baggage.get('sentry-public_key').toString(),
123124
release: baggage.get('sentry-release'),

dart/lib/src/sentry_tracer.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class SentryTracer extends ISentrySpan {
385385
transaction:
386386
_isHighQualityTransactionName(transactionNameSource) ? name : null,
387387
sampleRate: _sampleRateToString(_rootSpan.samplingDecision?.sampleRate),
388-
sampleRand: _sampleRateToString(_rootSpan.samplingDecision?.sampleRand),
388+
sampleRand: _sampleRandToString(_rootSpan.samplingDecision?.sampleRand),
389389
sampled: _rootSpan.samplingDecision?.sampled.toString(),
390390
);
391391

@@ -399,6 +399,13 @@ class SentryTracer extends ISentrySpan {
399399
return sampleRate != null ? SampleRateFormat().format(sampleRate) : null;
400400
}
401401

402+
String? _sampleRandToString(double? sampleRand) {
403+
if (!isValidSampleRand(sampleRand)) {
404+
return null;
405+
}
406+
return sampleRand != null ? SampleRateFormat().format(sampleRand) : null;
407+
}
408+
402409
bool _isHighQualityTransactionName(SentryTransactionNameSource source) {
403410
return source != SentryTransactionNameSource.url;
404411
}

dart/lib/src/sentry_traces_sampler.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SentryTracesSampler {
3333
try {
3434
final result = tracesSampler(samplingContext);
3535
if (result != null) {
36-
return _sample2(result);
36+
return _decideSampling(result);
3737
}
3838
} catch (exception, stackTrace) {
3939
_options.logger(
@@ -61,7 +61,7 @@ class SentryTracesSampler {
6161
double? optionsOrDefaultRate = optionsRate ?? defaultRate;
6262

6363
if (optionsOrDefaultRate != null) {
64-
return _sample2(optionsOrDefaultRate);
64+
return _decideSampling(optionsOrDefaultRate);
6565
}
6666

6767
return SentryTracesSamplingDecision(false);
@@ -75,7 +75,7 @@ class SentryTracesSampler {
7575
return _shouldSample(optionsRate);
7676
}
7777

78-
SentryTracesSamplingDecision _sample2(double sampleRate) {
78+
SentryTracesSamplingDecision _decideSampling(double sampleRate) {
7979
final sampleRand = _random.nextDouble();
8080
return SentryTracesSamplingDecision(
8181
_shouldSample(sampleRate, sampleRand: sampleRand),

dart/lib/src/sentry_transaction_context.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import 'tracing.dart';
88
@immutable
99
class SentryTransactionContext extends SentrySpanContext {
1010
final String name;
11-
final SentryTracesSamplingDecision? parentSamplingDecision;
1211
final SentryTransactionNameSource? transactionNameSource;
1312
final SentryTracesSamplingDecision? samplingDecision;
13+
final SentryTracesSamplingDecision? parentSamplingDecision;
1414

1515
SentryTransactionContext(
1616
this.name,
1717
String operation, {
1818
super.description,
19-
this.parentSamplingDecision,
2019
super.traceId,
2120
super.spanId,
2221
super.parentSpanId,
2322
this.transactionNameSource,
2423
this.samplingDecision,
24+
this.parentSamplingDecision,
2525
super.origin,
2626
}) : super(
2727
operation: operation,

dart/lib/src/utils/tracing_utils.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ bool isValidSampleRate(double? sampleRate) {
8080
}
8181
return !sampleRate.isNaN && sampleRate >= 0.0 && sampleRate <= 1.0;
8282
}
83+
84+
bool isValidSampleRand(double? sampleRand) {
85+
if (sampleRand == null) {
86+
return false;
87+
}
88+
return !sampleRand.isNaN && sampleRand >= 0.0 && sampleRand < 1.0;
89+
}

dart/test/protocol/sentry_baggage_header_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void main() {
2121
baggage.setUserSegment('userSegment');
2222
baggage.setTransaction('transaction');
2323
baggage.setSampleRate('1.0');
24+
baggage.setSampleRand('0.4');
2425
baggage.setSampled('false');
2526
final replayId = SentryId.newId().toString();
2627
baggage.setReplayId(replayId);
@@ -37,6 +38,7 @@ void main() {
3738
'sentry-user_segment=userSegment,'
3839
'sentry-transaction=transaction,'
3940
'sentry-sample_rate=1.0,'
41+
'sentry-sample_rand=0.4,'
4042
'sentry-sampled=false,'
4143
'sentry-replay_id=$replayId');
4244
});

dart/test/sentry_tracer_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ void main() {
487487
SentryTracesSamplingDecision(
488488
true,
489489
sampleRate: 1.0,
490+
sampleRand: 0.8,
490491
);
491492
final _context = SentryTransactionContext(
492493
'name',
@@ -512,6 +513,7 @@ void main() {
512513
expect(newBaggage.get('sentry-user_segment'), 'segment');
513514
expect(newBaggage.get('sentry-transaction'), 'name');
514515
expect(newBaggage.get('sentry-sample_rate'), '1');
516+
expect(newBaggage.getSampleRand(), 0.8);
515517
expect(newBaggage.get('sentry-sampled'), 'true');
516518
});
517519

0 commit comments

Comments
 (0)