Skip to content

Commit

Permalink
Merge branch 'main' into fix/app-lag-sff
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor authored Sep 26, 2024
2 parents c5d1299 + a4c4f8c commit b3716ec
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Emit `transaction.data` inside `contexts.trace.data` ([#2284](https://github.com/getsentry/sentry-dart/pull/2284))
- Blocking app starts if "appLaunchedInForeground" is false. (Android only) ([#2291](https://github.com/getsentry/sentry-dart/pull/2291)

### Enhancements
Expand Down
6 changes: 6 additions & 0 deletions dart/lib/src/protocol/sentry_trace_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class SentryTraceContext {
/// @see <https://develop.sentry.dev/sdk/performance/trace-origin>
final String? origin;

final Map<String, dynamic>? data;

@internal
final Map<String, dynamic>? unknown;

Expand All @@ -62,6 +64,7 @@ class SentryTraceContext {
: SpanStatus.fromString(json['status'] as String),
sampled: true,
origin: json['origin'] == null ? null : json['origin'] as String?,
data: json['data'] == null ? null : json['data'] as Map<String, dynamic>,
unknown: json.notAccessed(),
);
}
Expand All @@ -78,6 +81,7 @@ class SentryTraceContext {
if (description != null) 'description': description,
if (status != null) 'status': status!.toString(),
if (origin != null) 'origin': origin,
if (data != null) 'data': data,
};
}

Expand All @@ -92,6 +96,7 @@ class SentryTraceContext {
origin: origin,
unknown: unknown,
replayId: replayId,
data: data,
);

SentryTraceContext({
Expand All @@ -105,6 +110,7 @@ class SentryTraceContext {
this.origin,
this.unknown,
this.replayId,
this.data,
}) : traceId = traceId ?? SentryId.newId(),
spanId = spanId ?? SpanId.newId();

Expand Down
2 changes: 2 additions & 0 deletions dart/lib/src/protocol/sentry_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ class SentryTransaction extends SentryEvent {
this.metricSummaries =
metricSummaries ?? tracer.localMetricsAggregator?.getSummaries();

final data = extra ?? tracer.data;
contexts.trace = spanContext.toTraceContext(
sampled: tracer.samplingDecision?.sampled,
status: tracer.status,
data: data.isEmpty ? null : data,
);

this.transactionInfo = transactionInfo ??
Expand Down
2 changes: 2 additions & 0 deletions dart/lib/src/sentry_span_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SentrySpanContext {
SentryTraceContext toTraceContext({
bool? sampled,
SpanStatus? status,
Map<String, dynamic>? data,
}) {
return SentryTraceContext(
operation: operation,
Expand All @@ -63,6 +64,7 @@ class SentrySpanContext {
sampled: sampled,
status: status,
origin: origin,
data: data,
);
}
}
6 changes: 5 additions & 1 deletion dart/test/sentry_trace_context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
expect(map['status'], 'aborted');
expect(map['origin'], 'auto.ui');
expect(map['replay_id'], isNotNull);
expect(map['data'], {'key': 'value'});
});

test('fromJson deserializes', () {
Expand All @@ -30,7 +31,8 @@ void main() {
'description': 'desc',
'status': 'aborted',
'origin': 'auto.ui',
'replay_id': '00000000000000000000000000000004'
'replay_id': '00000000000000000000000000000004',
'data': {'key': 'value'},
};
map.addAll(testUnknown);
final traceContext = SentryTraceContext.fromJson(map);
Expand All @@ -44,6 +46,7 @@ void main() {
expect(traceContext.sampled, true);
expect(
traceContext.replayId.toString(), '00000000000000000000000000000004');
expect(traceContext.data, {'key': 'value'});
});
}

Expand All @@ -57,6 +60,7 @@ class Fixture {
status: SpanStatus.aborted(),
origin: 'auto.ui',
replayId: SentryId.newId(),
data: {'key': 'value'},
unknown: testUnknown,
);
}
Expand Down
23 changes: 23 additions & 0 deletions dart/test/sentry_transaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ void main() {
expect(sut.sampled, true);
});

test('returns contexts.trace.data if data is set', () async {
final tracer = _createTracer(sampled: true);
tracer.setData('key', 'value');
final child = tracer.startChild('child');
await child.finish();
await tracer.finish();

final sut = fixture.getSut(tracer);

expect(sut.contexts.trace!.data, {'key': 'value'});
});

test('returns null contexts.trace.data if data is not set', () async {
final tracer = _createTracer(sampled: true);
final child = tracer.startChild('child');
await child.finish();
await tracer.finish();

final sut = fixture.getSut(tracer);

expect(sut.contexts.trace!.data, isNull);
});

test('returns sampled false if not sampled', () async {
final tracer = _createTracer(sampled: false);
final child = tracer.startChild('child');
Expand Down

0 comments on commit b3716ec

Please sign in to comment.