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

Send DSN with SentryEnvelopeHeader #873

Closed
wants to merge 6 commits into from
Closed
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 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
4 changes: 4 additions & 0 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 @@ -56,13 +58,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
7 changes: 7 additions & 0 deletions dart/test/sentry_envelope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ void main() {
'trace_id': '${SentryId.newId()}',
'public_key': '123',
});
final fakeDsn = 'https://[email protected]/1234567';
final sut = SentryEnvelope.fromEvent(
sentryEvent,
sdkVersion,
dsn: fakeDsn,
traceContext: context,
);

Expand Down Expand Up @@ -136,16 +138,19 @@ void main() {
final sentryEvent = SentryEvent(eventId: eventId);
final sdkVersion =
SdkVersion(name: 'fixture-name', version: 'fixture-version');
final fakeDsn = 'https://[email protected]/1234567';

final sut = SentryEnvelope.fromEvent(
sentryEvent,
sdkVersion,
dsn: fakeDsn,
attachments: [attachment],
);

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

final sutEnvelopeData = <int>[];
Expand All @@ -165,12 +170,14 @@ void main() {
// This is a test for https://github.com/getsentry/sentry-dart/issues/523
test('serialize with non-serializable class', () async {
final event = SentryEvent(extra: {'non-ecodable': NonEncodable()});
final fakeDsn = 'https://[email protected]/1234567';
final sut = SentryEnvelope.fromEvent(
event,
SdkVersion(
name: 'test',
version: '1',
),
dsn: fakeDsn,
);

final _ = sut.envelopeStream(SentryOptions()).map((e) => e);
Expand Down
1 change: 0 additions & 1 deletion dart/test/sentry_envelope_vm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void main() {
final sdkVersion = SdkVersion(name: '', version: '');
final attachment =
IoSentryAttachment.fromPath('this_path_does_not_exist.txt');

final envelope = SentryEnvelope.fromEvent(
event,
sdkVersion,
Expand Down
31 changes: 19 additions & 12 deletions dart/test/transport/http_transport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/client_reports/discard_reason.dart';
import 'package:sentry/src/sentry_envelope_header.dart';
import 'package:sentry/src/sentry_envelope_item_header.dart';
import 'package:sentry/src/sentry_item_type.dart';
import 'package:sentry/src/sentry_tracer.dart';
import 'package:sentry/src/transport/data_category.dart';
import 'package:sentry/src/transport/http_transport.dart';
import 'package:sentry/src/transport/rate_limiter.dart';
import 'package:test/test.dart';
import 'package:sentry/src/sentry_tracer.dart';

import 'package:sentry/sentry.dart';
import 'package:sentry/src/transport/http_transport.dart';

import '../mocks.dart';
import '../mocks/mock_client_report_recorder.dart';
Expand Down Expand Up @@ -70,8 +69,10 @@ void main() {
final sut = fixture.getSut(httpMock, mockRateLimiter);

final sentryEvent = SentryEvent();
final envelope =
SentryEnvelope.fromEvent(sentryEvent, fixture.options.sdk);
final fakeDsn = 'https://[email protected]/1234567';
final envelope = SentryEnvelope.fromEvent(
sentryEvent, fixture.options.sdk,
dsn: fakeDsn);
await sut.send(envelope);

final envelopeData = <int>[];
Expand All @@ -94,8 +95,10 @@ void main() {
final sut = fixture.getSut(httpMock, mockRateLimiter);

final sentryEvent = SentryEvent();
final envelope =
SentryEnvelope.fromEvent(sentryEvent, fixture.options.sdk);
final fakeDsn = 'https://[email protected]/1234567';
final envelope = SentryEnvelope.fromEvent(
sentryEvent, fixture.options.sdk,
dsn: fakeDsn);
final eventId = await sut.send(envelope);

expect(eventId, SentryId.empty());
Expand All @@ -118,8 +121,10 @@ void main() {
final sut = fixture.getSut(httpMock, mockRateLimiter);

final sentryEvent = SentryEvent();
final envelope =
SentryEnvelope.fromEvent(sentryEvent, fixture.options.sdk);
final fakeDsn = 'https://[email protected]/1234567';
final envelope = SentryEnvelope.fromEvent(
sentryEvent, fixture.options.sdk,
dsn: fakeDsn);
await sut.send(envelope);

expect(mockRateLimiter.envelopeToFilter?.header.eventId,
Expand All @@ -139,8 +144,10 @@ void main() {
final sut = fixture.getSut(httpMock, mockRateLimiter);

final sentryEvent = SentryEvent();
final envelope =
SentryEnvelope.fromEvent(sentryEvent, fixture.options.sdk);
final fakeDsn = 'https://[email protected]/1234567';
final envelope = SentryEnvelope.fromEvent(
sentryEvent, fixture.options.sdk,
dsn: fakeDsn);
await sut.send(envelope);

expect(mockRateLimiter.errorCode, 200);
Expand Down
1 change: 1 addition & 0 deletions dio/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ typedef EventProcessorFunction = FutureOr<SentryEvent?>
var fakeEnvelope = SentryEnvelope.fromEvent(
fakeEvent,
SdkVersion(name: 'sdk1', version: '1.0.0'),
dsn: fakeDsn,
);

class MockRateLimiter implements RateLimiter {
Expand Down
9 changes: 6 additions & 3 deletions flutter/test/file_system_transport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ void main() {
final event = SentryEvent();
final sdkVersion =
SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion');
final fakeDsn = 'https://[email protected]/1234567';

final envelope = SentryEnvelope.fromEvent(event, sdkVersion);
final envelope = SentryEnvelope.fromEvent(event, sdkVersion, dsn: fakeDsn);
final sentryId = await transport.send(envelope);

expect(sentryId, sentryId);
Expand All @@ -48,8 +49,9 @@ void main() {
final event = SentryEvent();
final sdkVersion =
SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion');
final fakeDsn = 'https://[email protected]/1234567';

final envelope = SentryEnvelope.fromEvent(event, sdkVersion);
final envelope = SentryEnvelope.fromEvent(event, sdkVersion, dsn: fakeDsn);
final sentryId = await transport.send(envelope);

expect(SentryId.empty(), sentryId);
Expand All @@ -67,7 +69,8 @@ void main() {
SentryEvent(message: SentryMessage('hi I am a special char ◤'));
final sdkVersion =
SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion');
final envelope = SentryEnvelope.fromEvent(event, sdkVersion);
final fakeDsn = 'https://[email protected]/1234567';
final envelope = SentryEnvelope.fromEvent(event, sdkVersion, dsn: fakeDsn);
await transport.send(envelope);

final envelopeList = arguments as List;
Expand Down