Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit transaction.data in contexts.trace.data #2284

Merged
merged 7 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@
/// @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 @@
: 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 @@
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 @@
origin: origin,
unknown: unknown,
replayId: replayId,
data: data,

Check warning on line 99 in dart/lib/src/protocol/sentry_trace_context.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/protocol/sentry_trace_context.dart#L99

Added line #L99 was not covered by tests
);

SentryTraceContext({
Expand All @@ -105,6 +110,7 @@
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
Loading