File tree Expand file tree Collapse file tree 7 files changed +26
-7
lines changed Expand file tree Collapse file tree 7 files changed +26
-7
lines changed Original file line number Diff line number Diff 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' ),
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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),
Original file line number Diff line number Diff line change @@ -8,20 +8,20 @@ import 'tracing.dart';
88@immutable
99class 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,
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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 });
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments