diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index b250badf7e..a10c52079e 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -133,6 +133,7 @@ class SentryClient { final envelope = SentryEnvelope.fromEvent( preparedEvent, _options.sdk, + dsn: _options.dsn, traceContext: scope?.span?.traceContext(), attachments: scope?.attachments, ); diff --git a/dart/lib/src/sentry_envelope.dart b/dart/lib/src/sentry_envelope.dart index f090e26ea3..450a3bb8d3 100644 --- a/dart/lib/src/sentry_envelope.dart +++ b/dart/lib/src/sentry_envelope.dart @@ -24,6 +24,7 @@ class SentryEnvelope { factory SentryEnvelope.fromEvent( SentryEvent event, SdkVersion sdkVersion, { + String? dsn, SentryTraceContextHeader? traceContext, List? attachments, }) { @@ -31,6 +32,7 @@ class SentryEnvelope { SentryEnvelopeHeader( event.eventId, sdkVersion, + dsn: dsn, traceContext: traceContext, ), [ @@ -56,6 +58,7 @@ class SentryEnvelope { factory SentryEnvelope.fromTransaction( SentryTransaction transaction, SdkVersion sdkVersion, { + String? dsn, SentryTraceContextHeader? traceContext, List? attachments, }) { @@ -63,6 +66,7 @@ class SentryEnvelope { SentryEnvelopeHeader( transaction.eventId, sdkVersion, + dsn: dsn, traceContext: traceContext, ), [ diff --git a/dart/lib/src/sentry_envelope_header.dart b/dart/lib/src/sentry_envelope_header.dart index 5fe941ab04..c6b2bb9ead 100644 --- a/dart/lib/src/sentry_envelope_header.dart +++ b/dart/lib/src/sentry_envelope_header.dart @@ -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`. @@ -22,6 +24,9 @@ class SentryEnvelopeHeader { final SentryTraceContextHeader? traceContext; + /// The `DSN` of the Sentry project. + final String? dsn; + /// Header encoded as JSON Map toJson() { final json = {}; @@ -41,6 +46,9 @@ class SentryEnvelopeHeader { json['trace'] = tempTraceContext.toJson(); } + if (dsn != null) { + json['dsn'] = dsn; + } return json; } } diff --git a/dart/test/mocks.dart b/dart/test/mocks.dart index cb36172d06..836dccc762 100644 --- a/dart/test/mocks.dart +++ b/dart/test/mocks.dart @@ -129,7 +129,10 @@ typedef EventProcessorFunction = FutureOr 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; diff --git a/dart/test/sentry_envelope_test.dart b/dart/test/sentry_envelope_test.dart index c7c683995a..d5b24a9d92 100644 --- a/dart/test/sentry_envelope_test.dart +++ b/dart/test/sentry_envelope_test.dart @@ -64,9 +64,11 @@ void main() { 'trace_id': '${SentryId.newId()}', 'public_key': '123', }); + final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; final sut = SentryEnvelope.fromEvent( sentryEvent, sdkVersion, + dsn: fakeDsn, traceContext: context, ); @@ -136,16 +138,19 @@ void main() { final sentryEvent = SentryEvent(eventId: eventId); final sdkVersion = SdkVersion(name: 'fixture-name', version: 'fixture-version'); + final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; final sut = SentryEnvelope.fromEvent( sentryEvent, sdkVersion, + dsn: fakeDsn, attachments: [attachment], ); final expectedEnvelopeItem = SentryEnvelope.fromEvent( sentryEvent, sdkVersion, + dsn: fakeDsn, ); final sutEnvelopeData = []; @@ -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://abc@def.ingest.sentry.io/1234567'; final sut = SentryEnvelope.fromEvent( event, SdkVersion( name: 'test', version: '1', ), + dsn: fakeDsn, ); final _ = sut.envelopeStream(SentryOptions()).map((e) => e); diff --git a/dart/test/sentry_envelope_vm_test.dart b/dart/test/sentry_envelope_vm_test.dart index 33dce0515d..fdb136d9d6 100644 --- a/dart/test/sentry_envelope_vm_test.dart +++ b/dart/test/sentry_envelope_vm_test.dart @@ -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, diff --git a/dart/test/transport/http_transport_test.dart b/dart/test/transport/http_transport_test.dart index d6394c9c3f..e8df1cf372 100644 --- a/dart/test/transport/http_transport_test.dart +++ b/dart/test/transport/http_transport_test.dart @@ -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'; @@ -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://abc@def.ingest.sentry.io/1234567'; + final envelope = SentryEnvelope.fromEvent( + sentryEvent, fixture.options.sdk, + dsn: fakeDsn); await sut.send(envelope); final envelopeData = []; @@ -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://abc@def.ingest.sentry.io/1234567'; + final envelope = SentryEnvelope.fromEvent( + sentryEvent, fixture.options.sdk, + dsn: fakeDsn); final eventId = await sut.send(envelope); expect(eventId, SentryId.empty()); @@ -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://abc@def.ingest.sentry.io/1234567'; + final envelope = SentryEnvelope.fromEvent( + sentryEvent, fixture.options.sdk, + dsn: fakeDsn); await sut.send(envelope); expect(mockRateLimiter.envelopeToFilter?.header.eventId, @@ -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://abc@def.ingest.sentry.io/1234567'; + final envelope = SentryEnvelope.fromEvent( + sentryEvent, fixture.options.sdk, + dsn: fakeDsn); await sut.send(envelope); expect(mockRateLimiter.errorCode, 200); diff --git a/dio/test/mocks.dart b/dio/test/mocks.dart index b17a27e8b6..f12bc2c4aa 100644 --- a/dio/test/mocks.dart +++ b/dio/test/mocks.dart @@ -131,6 +131,7 @@ typedef EventProcessorFunction = FutureOr var fakeEnvelope = SentryEnvelope.fromEvent( fakeEvent, SdkVersion(name: 'sdk1', version: '1.0.0'), + dsn: fakeDsn, ); class MockRateLimiter implements RateLimiter { diff --git a/flutter/test/file_system_transport_test.dart b/flutter/test/file_system_transport_test.dart index 6d066d53c7..fccb953ac8 100644 --- a/flutter/test/file_system_transport_test.dart +++ b/flutter/test/file_system_transport_test.dart @@ -32,8 +32,9 @@ void main() { final event = SentryEvent(); final sdkVersion = SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion'); + final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; - final envelope = SentryEnvelope.fromEvent(event, sdkVersion); + final envelope = SentryEnvelope.fromEvent(event, sdkVersion, dsn: fakeDsn); final sentryId = await transport.send(envelope); expect(sentryId, sentryId); @@ -48,8 +49,9 @@ void main() { final event = SentryEvent(); final sdkVersion = SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion'); + final fakeDsn = 'https://abc@def.ingest.sentry.io/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); @@ -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://abc@def.ingest.sentry.io/1234567'; + final envelope = SentryEnvelope.fromEvent(event, sdkVersion, dsn: fakeDsn); await transport.send(envelope); final envelopeList = arguments as List;