Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add sampled flag
  • Loading branch information
buenaflor committed Sep 12, 2023
commit 1e13d21476aaa0862177a5076080e8d262a9fbe0
4 changes: 4 additions & 0 deletions dart/lib/src/sentry_baggage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ class SentryBaggage {
set(_sampleRateKeyName, value);
}

void setSampled(String value) {
set('sentry-sampled', value);
}

double? getSampleRate() {
final sampleRate = get(_sampleRateKeyName);
if (sampleRate == null) {
Expand Down
8 changes: 7 additions & 1 deletion dart/lib/src/sentry_trace_context_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SentryTraceContextHeader {
this.userSegment,
this.transaction,
this.sampleRate,
this.sampled,
});

final SentryId traceId;
Expand All @@ -22,6 +23,7 @@ class SentryTraceContextHeader {
final String? userSegment;
final String? transaction;
final String? sampleRate;
final String? sampled;

/// Deserializes a [SentryTraceContextHeader] from JSON [Map].
factory SentryTraceContextHeader.fromJson(Map<String, dynamic> json) {
Expand All @@ -34,6 +36,7 @@ class SentryTraceContextHeader {
userSegment: json['user_segment'],
transaction: json['transaction'],
sampleRate: json['sample_rate'],
sampled: json['sampled'],
);
}

Expand All @@ -48,6 +51,7 @@ class SentryTraceContextHeader {
if (userSegment != null) 'user_segment': userSegment,
if (transaction != null) 'transaction': transaction,
if (sampleRate != null) 'sample_rate': sampleRate,
if (sampled != null) 'sampled': sampled,
};
}

Expand Down Expand Up @@ -76,7 +80,9 @@ class SentryTraceContextHeader {
if (sampleRate != null) {
baggage.setSampleRate(sampleRate!);
}

if (sampled != null) {
baggage.setSampled(sampled!);
}
return baggage;
}

Expand Down
1 change: 1 addition & 0 deletions dart/lib/src/sentry_tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class SentryTracer extends ISentrySpan {
transaction:
_isHighQualityTransactionName(transactionNameSource) ? name : null,
sampleRate: _sampleRateToString(_rootSpan.samplingDecision?.sampleRate),
sampled: _rootSpan.samplingDecision?.sampled.toString(),
);

return _sentryTraceContextHeader;
Expand Down
3 changes: 2 additions & 1 deletion dart/test/protocol/sentry_baggage_header_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ void main() {
baggage.setUserSegment('userSegment');
baggage.setTransaction('transaction');
baggage.setSampleRate('1.0');
baggage.setSampled('false');

final baggageHeader = SentryBaggageHeader.fromBaggage(baggage);

expect(baggageHeader.value,
'sentry-trace_id=$id,sentry-public_key=publicKey,sentry-release=release,sentry-environment=environment,sentry-user_id=userId,sentry-user_segment=userSegment,sentry-transaction=transaction,sentry-sample_rate=1.0');
'sentry-trace_id=$id,sentry-public_key=publicKey,sentry-release=release,sentry-environment=environment,sentry-user_id=userId,sentry-user_segment=userSegment,sentry-transaction=transaction,sentry-sample_rate=1.0,sentry-sampled=false');
});
});
}
4 changes: 3 additions & 1 deletion dart/test/sentry_trace_context_header_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() {
'user_segment': 'user_segment',
'transaction': 'transaction',
'sample_rate': '1.0',
'sampled': 'false'
};
final context = SentryTraceContextHeader.fromJson(mapJson);

Expand All @@ -26,6 +27,7 @@ void main() {
expect(context.userSegment, 'user_segment');
expect(context.transaction, 'transaction');
expect(context.sampleRate, '1.0');
expect(context.sampled, 'false');
});

test('toJson', () {
Expand All @@ -38,7 +40,7 @@ void main() {
final baggage = context.toBaggage();

expect(baggage.toHeaderString(),
'sentry-trace_id=${id.toString()},sentry-public_key=123,sentry-release=release,sentry-environment=environment,sentry-user_id=user_id,sentry-user_segment=user_segment,sentry-transaction=transaction,sentry-sample_rate=1.0');
'sentry-trace_id=${id.toString()},sentry-public_key=123,sentry-release=release,sentry-environment=environment,sentry-user_id=user_id,sentry-user_segment=user_segment,sentry-transaction=transaction,sentry-sample_rate=1.0,sentry-sampled=false');
});
});
}
2 changes: 2 additions & 0 deletions dart/test/sentry_tracer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ void main() {
expect(newBaggage.get('sentry-user_segment'), 'segment');
expect(newBaggage.get('sentry-transaction'), 'name');
expect(newBaggage.get('sentry-sample_rate'), '1');
expect(newBaggage.get('sentry-sampled'), 'true');
});

test('skip transaction name if low cardinality', () {
Expand Down Expand Up @@ -562,6 +563,7 @@ void main() {
expect(context.userSegment, 'segment');
expect(context.transaction, 'name');
expect(context.sampleRate, '1');
expect(context.sampled, 'true');
});
});
}
Expand Down