Skip to content

Commit a4c4f8c

Browse files
authored
Emit transaction.data in contexts.trace.data (#2284)
* add * set data to null if empty * update testn ame * Add CHANGELOG entry
1 parent bf8d36c commit a4c4f8c

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

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

910
### Enhancements

dart/lib/src/protocol/sentry_trace_context.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class SentryTraceContext {
4141
/// @see <https://develop.sentry.dev/sdk/performance/trace-origin>
4242
final String? origin;
4343

44+
final Map<String, dynamic>? data;
45+
4446
@internal
4547
final Map<String, dynamic>? unknown;
4648

@@ -62,6 +64,7 @@ class SentryTraceContext {
6264
: SpanStatus.fromString(json['status'] as String),
6365
sampled: true,
6466
origin: json['origin'] == null ? null : json['origin'] as String?,
67+
data: json['data'] == null ? null : json['data'] as Map<String, dynamic>,
6568
unknown: json.notAccessed(),
6669
);
6770
}
@@ -78,6 +81,7 @@ class SentryTraceContext {
7881
if (description != null) 'description': description,
7982
if (status != null) 'status': status!.toString(),
8083
if (origin != null) 'origin': origin,
84+
if (data != null) 'data': data,
8185
};
8286
}
8387

@@ -92,6 +96,7 @@ class SentryTraceContext {
9296
origin: origin,
9397
unknown: unknown,
9498
replayId: replayId,
99+
data: data,
95100
);
96101

97102
SentryTraceContext({
@@ -105,6 +110,7 @@ class SentryTraceContext {
105110
this.origin,
106111
this.unknown,
107112
this.replayId,
113+
this.data,
108114
}) : traceId = traceId ?? SentryId.newId(),
109115
spanId = spanId ?? SpanId.newId();
110116

dart/lib/src/protocol/sentry_transaction.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ class SentryTransaction extends SentryEvent {
5757
this.metricSummaries =
5858
metricSummaries ?? tracer.localMetricsAggregator?.getSummaries();
5959

60+
final data = extra ?? tracer.data;
6061
contexts.trace = spanContext.toTraceContext(
6162
sampled: tracer.samplingDecision?.sampled,
6263
status: tracer.status,
64+
data: data.isEmpty ? null : data,
6365
);
6466

6567
this.transactionInfo = transactionInfo ??

dart/lib/src/sentry_span_context.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class SentrySpanContext {
5353
SentryTraceContext toTraceContext({
5454
bool? sampled,
5555
SpanStatus? status,
56+
Map<String, dynamic>? data,
5657
}) {
5758
return SentryTraceContext(
5859
operation: operation,
@@ -63,6 +64,7 @@ class SentrySpanContext {
6364
sampled: sampled,
6465
status: status,
6566
origin: origin,
67+
data: data,
6668
);
6769
}
6870
}

dart/test/sentry_trace_context_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void main() {
1919
expect(map['status'], 'aborted');
2020
expect(map['origin'], 'auto.ui');
2121
expect(map['replay_id'], isNotNull);
22+
expect(map['data'], {'key': 'value'});
2223
});
2324

2425
test('fromJson deserializes', () {
@@ -30,7 +31,8 @@ void main() {
3031
'description': 'desc',
3132
'status': 'aborted',
3233
'origin': 'auto.ui',
33-
'replay_id': '00000000000000000000000000000004'
34+
'replay_id': '00000000000000000000000000000004',
35+
'data': {'key': 'value'},
3436
};
3537
map.addAll(testUnknown);
3638
final traceContext = SentryTraceContext.fromJson(map);
@@ -44,6 +46,7 @@ void main() {
4446
expect(traceContext.sampled, true);
4547
expect(
4648
traceContext.replayId.toString(), '00000000000000000000000000000004');
49+
expect(traceContext.data, {'key': 'value'});
4750
});
4851
}
4952

@@ -57,6 +60,7 @@ class Fixture {
5760
status: SpanStatus.aborted(),
5861
origin: 'auto.ui',
5962
replayId: SentryId.newId(),
63+
data: {'key': 'value'},
6064
unknown: testUnknown,
6165
);
6266
}

dart/test/sentry_transaction_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ void main() {
6565
expect(sut.sampled, true);
6666
});
6767

68+
test('returns contexts.trace.data if data is set', () async {
69+
final tracer = _createTracer(sampled: true);
70+
tracer.setData('key', 'value');
71+
final child = tracer.startChild('child');
72+
await child.finish();
73+
await tracer.finish();
74+
75+
final sut = fixture.getSut(tracer);
76+
77+
expect(sut.contexts.trace!.data, {'key': 'value'});
78+
});
79+
80+
test('returns null contexts.trace.data if data is not set', () async {
81+
final tracer = _createTracer(sampled: true);
82+
final child = tracer.startChild('child');
83+
await child.finish();
84+
await tracer.finish();
85+
86+
final sut = fixture.getSut(tracer);
87+
88+
expect(sut.contexts.trace!.data, isNull);
89+
});
90+
6891
test('returns sampled false if not sampled', () async {
6992
final tracer = _createTracer(sampled: false);
7093
final child = tracer.startChild('child');

0 commit comments

Comments
 (0)