Skip to content
Closed
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
Prev Previous commit
Next Next commit
Merge branch 'main' into sentry_tunnel
  • Loading branch information
ua741 committed Sep 27, 2022
commit 152d32a18287bea0d612704a0e20630fb254164c
5 changes: 3 additions & 2 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ class SentryClient {
final envelope = SentryEnvelope.fromEvent(
preparedEvent,
_options.sdk,
_options.dsn,
attachments: scope?.attachements,
dsn: _options.dsn,
traceContext: scope?.span?.traceContext(),
attachments: scope?.attachments,
);

final id = await captureEnvelope(envelope);
Expand Down
23 changes: 18 additions & 5 deletions dart/lib/src/sentry_envelope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ class SentryEnvelope {
/// Create an [SentryEnvelope] with containing one [SentryEnvelopeItem] which holds the [SentryEvent] data.
factory SentryEnvelope.fromEvent(
SentryEvent event,
SdkVersion sdkVersion,
String? dsn, {
SdkVersion sdkVersion, {
String? dsn,
SentryTraceContextHeader? traceContext,
List<SentryAttachment>? attachments,
}) {
return SentryEnvelope(
SentryEnvelopeHeader(event.eventId, sdkVersion, dsn),
SentryEnvelopeHeader(
event.eventId,
sdkVersion,
dsn: dsn,
traceContext: traceContext,
),
[
SentryEnvelopeItem.fromEvent(event),
if (attachments != null)
Expand All @@ -42,7 +48,8 @@ class SentryEnvelope {
SdkVersion sdkVersion,
) {
return SentryEnvelope(
SentryEnvelopeHeader(feedback.eventId, sdkVersion, null),
// no need for [traceContext]
SentryEnvelopeHeader(feedback.eventId, sdkVersion),
[SentryEnvelopeItem.fromUserFeedback(feedback)],
);
}
Expand All @@ -51,11 +58,17 @@ class SentryEnvelope {
factory SentryEnvelope.fromTransaction(
SentryTransaction transaction,
SdkVersion sdkVersion, {
String? dsn,
SentryTraceContextHeader? traceContext,
List<SentryAttachment>? attachments,
}) {
return SentryEnvelope(
SentryEnvelopeHeader(transaction.eventId, sdkVersion, null),
SentryEnvelopeHeader(
transaction.eventId,
sdkVersion,
dsn: dsn,
traceContext: traceContext,
),
[
SentryEnvelopeItem.fromTransaction(transaction),
if (attachments != null)
Expand Down
18 changes: 16 additions & 2 deletions dart/lib/src/sentry_envelope_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ import 'sentry_trace_context_header.dart';

/// Header containing `SentryId` and `SdkVersion`.
class SentryEnvelopeHeader {
SentryEnvelopeHeader(this.eventId, this.sdkVersion, this.dsn);
SentryEnvelopeHeader(
this.eventId,
this.sdkVersion, {
this.dsn,
this.traceContext,
});
SentryEnvelopeHeader.newEventId()
: eventId = SentryId.newId(),
sdkVersion = null,
dsn = null;
dsn = null,
traceContext = null;

/// The identifier of encoded `SentryEvent`.
final SentryId? eventId;

/// The `SdkVersion` with which the envelope was send.
final SdkVersion? sdkVersion;

final SentryTraceContextHeader? traceContext;

/// The `DSN` of the Sentry project.
final String? dsn;

Expand All @@ -32,6 +40,12 @@ class SentryEnvelopeHeader {
if (tempSdkVersion != null) {
json['sdk'] = tempSdkVersion.toJson();
}

final tempTraceContext = traceContext;
if (tempTraceContext != null) {
json['trace'] = tempTraceContext.toJson();
}

if (dsn != null) {
json['dsn'] = dsn;
}
Expand Down
10 changes: 9 additions & 1 deletion dart/test/sentry_envelope_header_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ void main() {
name: 'fixture-sdkName',
version: 'fixture-version',
);
final sut = SentryEnvelopeHeader(eventId, sdkVersion, null);
final context = SentryTraceContextHeader.fromJson(<String, dynamic>{
'trace_id': '${SentryId.newId()}',
'public_key': '123',
});
final sut = SentryEnvelopeHeader(
eventId,
sdkVersion,
traceContext: context,
);
final expextedSkd = sdkVersion.toJson();
final expected = <String, dynamic>{
'event_id': eventId.toString(),
Expand Down
22 changes: 19 additions & 3 deletions dart/test/sentry_envelope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ void main() {

final item = SentryEnvelopeItem(itemHeader, dataFactory);

final header = SentryEnvelopeHeader(eventId, null, null);
final context = SentryTraceContextHeader.fromJson(<String, dynamic>{
'trace_id': '${SentryId.newId()}',
'public_key': '123',
});
final header = SentryEnvelopeHeader(
eventId,
null,
traceContext: context,
);
final sut = SentryEnvelope(header, [item, item]);

final expectedHeaderJson = header.toJson();
Expand All @@ -52,9 +60,17 @@ void main() {
final sentryEvent = SentryEvent(eventId: eventId);
final sdkVersion =
SdkVersion(name: 'fixture-name', version: 'fixture-version');
final context = SentryTraceContextHeader.fromJson(<String, dynamic>{
'trace_id': '${SentryId.newId()}',
'public_key': '123',
});
final fakeDsn = 'https://[email protected]/1234567';
final sut =
SentryEnvelope.fromEvent(sentryEvent, sdkVersion, fakeDsn);
final sut = SentryEnvelope.fromEvent(
sentryEvent,
sdkVersion,
dsn: fakeDsn,
traceContext: context,
);

final expectedEnvelopeItem = SentryEnvelopeItem.fromEvent(sentryEvent);

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.