Skip to content

Commit

Permalink
Added missing DSN field into the SentryEnvelopeHeade (#1050)
Browse files Browse the repository at this point in the history
Co-authored-by: vishnukvmd <[email protected]>
Co-authored-by: Neeraj Gupta <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2022
1 parent b8b9b7b commit fe217ba
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 262 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CHANGELOG.md merge=union
* text=auto eol=lf
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Features

- Added [Flutter renderer](https://docs.flutter.dev/development/platform-integration/web/renderers) information to events ([#1035](https://github.com/getsentry/sentry-dart/pull/1035))
- Added missing DSN field into the SentryEnvelopeHeader ([#1050](https://github.com/getsentry/sentry-dart/pull/1050))

### Dependencies

Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class SentryClient {
final envelope = SentryEnvelope.fromEvent(
preparedEvent,
_options.sdk,
dsn: _options.dsn,
traceContext: scope?.span?.traceContext(),
attachments: scope?.attachments,
);
Expand Down Expand Up @@ -318,6 +319,7 @@ class SentryClient {
final envelope = SentryEnvelope.fromTransaction(
preparedTransaction,
_options.sdk,
dsn: _options.dsn,
traceContext: traceContext,
attachments: attachments,
);
Expand All @@ -336,6 +338,7 @@ class SentryClient {
final envelope = SentryEnvelope.fromUserFeedback(
userFeedback,
_options.sdk,
dsn: _options.dsn,
);
return _attachClientReportsAndSend(envelope);
}
Expand Down
15 changes: 12 additions & 3 deletions dart/lib/src/sentry_envelope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class SentryEnvelope {
factory SentryEnvelope.fromEvent(
SentryEvent event,
SdkVersion sdkVersion, {
String? dsn,
SentryTraceContextHeader? traceContext,
List<SentryAttachment>? attachments,
}) {
return SentryEnvelope(
SentryEnvelopeHeader(
event.eventId,
sdkVersion,
dsn: dsn,
traceContext: traceContext,
),
[
Expand All @@ -43,11 +45,16 @@ class SentryEnvelope {

factory SentryEnvelope.fromUserFeedback(
SentryUserFeedback feedback,
SdkVersion sdkVersion,
) {
SdkVersion sdkVersion, {
String? dsn,
}) {
return SentryEnvelope(
// no need for [traceContext]
SentryEnvelopeHeader(feedback.eventId, sdkVersion),
SentryEnvelopeHeader(
feedback.eventId,
sdkVersion,
dsn: dsn,
),
[SentryEnvelopeItem.fromUserFeedback(feedback)],
);
}
Expand All @@ -56,13 +63,15 @@ class SentryEnvelope {
factory SentryEnvelope.fromTransaction(
SentryTransaction transaction,
SdkVersion sdkVersion, {
String? dsn,
SentryTraceContextHeader? traceContext,
List<SentryAttachment>? attachments,
}) {
return SentryEnvelope(
SentryEnvelopeHeader(
transaction.eventId,
sdkVersion,
dsn: dsn,
traceContext: traceContext,
),
[
Expand Down
8 changes: 8 additions & 0 deletions dart/lib/src/sentry_envelope_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class SentryEnvelopeHeader {
SentryEnvelopeHeader(
this.eventId,
this.sdkVersion, {
this.dsn,
this.traceContext,
});
SentryEnvelopeHeader.newEventId()
: eventId = SentryId.newId(),
sdkVersion = null,
dsn = null,
traceContext = null;

/// The identifier of encoded `SentryEvent`.
Expand All @@ -22,6 +24,9 @@ class SentryEnvelopeHeader {

final SentryTraceContextHeader? traceContext;

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

/// Header encoded as JSON
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
Expand All @@ -41,6 +46,9 @@ class SentryEnvelopeHeader {
json['trace'] = tempTraceContext.toJson();
}

if (dsn != null) {
json['dsn'] = dsn;
}
return json;
}
}
5 changes: 4 additions & 1 deletion dart/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ typedef EventProcessorFunction = FutureOr<SentryEvent?>
Function(SentryEvent event, {dynamic hint});

var fakeEnvelope = SentryEnvelope.fromEvent(
fakeEvent, SdkVersion(name: 'sdk1', version: '1.0.0'));
fakeEvent,
SdkVersion(name: 'sdk1', version: '1.0.0'),
dsn: fakeDsn,
);

class MockRateLimiter implements RateLimiter {
bool filterReturnsNull = false;
Expand Down
34 changes: 34 additions & 0 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ void main() {

expect(capturedEvent.threads?.first.stacktrace, isNull);
});

test('event envelope contains dsn', () async {
final client = fixture.getSut();
final event = SentryEvent();
await client.captureEvent(event);

final capturedEnvelope = (fixture.transport).envelopes.first;

expect(capturedEnvelope.header.dsn, fixture.options.dsn);
});
});

group('SentryClient captures exception', () {
Expand Down Expand Up @@ -468,6 +478,16 @@ void main() {

expect(id, SentryId.empty());
});

test('transaction envelope contains dsn', () async {
final client = fixture.getSut();
final tr = SentryTransaction(fixture.tracer);
await client.captureTransaction(tr);

final capturedEnvelope = (fixture.transport).envelopes.first;

expect(capturedEnvelope.header.dsn, fixture.options.dsn);
});
});

group('SentryClient : apply scope to the captured event', () {
Expand Down Expand Up @@ -1193,6 +1213,20 @@ void main() {
expect(fixture.recorder.reason, DiscardReason.sampleRate);
expect(fixture.recorder.category, DataCategory.error);
});

test('user feedback envelope contains dsn', () async {
final client = fixture.getSut();
final event = SentryEvent();
final feedback = SentryUserFeedback(
eventId: event.eventId,
name: 'test',
);
await client.captureUserFeedback(feedback);

final capturedEnvelope = (fixture.transport).envelopes.first;

expect(capturedEnvelope.header.dsn, fixture.options.dsn);
});
});
}

Expand Down
4 changes: 4 additions & 0 deletions dart/test/sentry_envelope_header_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:sentry/sentry.dart';
import 'package:sentry/src/sentry_envelope_header.dart';
import 'package:test/test.dart';

import 'mocks.dart';

void main() {
group('SentryEnvelopeHeader', () {
test('toJson empty', () {
Expand All @@ -23,13 +25,15 @@ void main() {
final sut = SentryEnvelopeHeader(
eventId,
sdkVersion,
dsn: fakeDsn,
traceContext: context,
);
final expextedSkd = sdkVersion.toJson();
final expected = <String, dynamic>{
'event_id': eventId.toString(),
'sdk': expextedSkd,
'trace': context.toJson(),
'dsn': fakeDsn,
};
expect(sut.toJson(), expected);
});
Expand Down
8 changes: 8 additions & 0 deletions dart/test/sentry_envelope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:sentry/src/sentry_tracer.dart';
import 'package:sentry/src/utils.dart';
import 'package:test/test.dart';

import 'mocks.dart';
import 'mocks/mock_hub.dart';

void main() {
Expand Down Expand Up @@ -67,6 +68,7 @@ void main() {
final sut = SentryEnvelope.fromEvent(
sentryEvent,
sdkVersion,
dsn: fakeDsn,
traceContext: context,
);

Expand All @@ -75,6 +77,7 @@ void main() {
expect(sut.header.eventId, eventId);
expect(sut.header.sdkVersion, sdkVersion);
expect(sut.header.traceContext, context);
expect(sut.header.dsn, fakeDsn);
expect(sut.items[0].header.contentType,
expectedEnvelopeItem.header.contentType);
expect(sut.items[0].header.type, expectedEnvelopeItem.header.type);
Expand Down Expand Up @@ -105,6 +108,7 @@ void main() {
final sut = SentryEnvelope.fromTransaction(
tr,
sdkVersion,
dsn: fakeDsn,
traceContext: traceContext,
);

Expand All @@ -113,6 +117,7 @@ void main() {
expect(sut.header.eventId, tr.eventId);
expect(sut.header.sdkVersion, sdkVersion);
expect(sut.header.traceContext, traceContext);
expect(sut.header.dsn, fakeDsn);
expect(sut.items[0].header.contentType,
expectedEnvelopeItem.header.contentType);
expect(sut.items[0].header.type, expectedEnvelopeItem.header.type);
Expand Down Expand Up @@ -140,12 +145,14 @@ void main() {
final sut = SentryEnvelope.fromEvent(
sentryEvent,
sdkVersion,
dsn: fakeDsn,
attachments: [attachment],
);

final expectedEnvelopeItem = SentryEnvelope.fromEvent(
sentryEvent,
sdkVersion,
dsn: fakeDsn,
);

final sutEnvelopeData = <int>[];
Expand All @@ -171,6 +178,7 @@ void main() {
name: 'test',
version: '1',
),
dsn: fakeDsn,
);

final _ = sut.envelopeStream(SentryOptions()).map((e) => e);
Expand Down
Loading

0 comments on commit fe217ba

Please sign in to comment.