Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a10d740
remove the SentryResponse class
rxlabz Oct 21, 2020
623c904
refactor : add a Transport class
rxlabz Oct 21, 2020
0dcb613
refactor : move the clock initialization to Transport
rxlabz Oct 21, 2020
c97c98b
- refactor : applyScope
rxlabz Oct 21, 2020
477fdac
changelog
rxlabz Oct 21, 2020
b8fb322
fix merge conflicts
rxlabz Oct 22, 2020
fd92e3f
Merge branch 'feature/unified-api' into ref/transport
rxlabz Oct 22, 2020
0944c68
move the headers definition strategy to transport
rxlabz Oct 22, 2020
46829fc
- Instantiate Transport from options
rxlabz Oct 22, 2020
01d4e19
handle event dropping in event processors
rxlabz Oct 22, 2020
fbd001e
fix client._applyScope : merge event and scope tags and extra
rxlabz Oct 22, 2020
4d39531
remove client.toString()
rxlabz Oct 22, 2020
34fb528
fix a test
rxlabz Oct 22, 2020
2437fa4
Merge branch 'feature/unified-api' into ref/transport
rxlabz Oct 22, 2020
57798f5
handle the event serialization in the transport layer
rxlabz Oct 22, 2020
789e154
Merge remote-tracking branch 'origin/feature/unified-api' into ref/tr…
rxlabz Oct 22, 2020
1aa05d6
remove stackFrameFilter references
rxlabz Oct 22, 2020
9895142
Merge remote-tracking branch 'origin/feature/unified-api' into ref/tr…
rxlabz Oct 22, 2020
cb5e309
add a CredentialBuilder
rxlabz Oct 22, 2020
e563d2c
- headers configuration
rxlabz Oct 23, 2020
71b53c8
- fix scope.level precedence
rxlabz Oct 23, 2020
be3f0a2
buildHeaders and fix timestamp test
rxlabz Oct 23, 2020
43b798c
- add a isWeb helper to define the event.platform
rxlabz Oct 23, 2020
19dc91d
feat: apply sample rate
marandaneto Oct 23, 2020
cec1f21
changelog
marandaneto Oct 23, 2020
909d4f9
- add a isWeb helper to define the event.platform and sdkName
rxlabz Oct 23, 2020
8b600dc
- add a isWeb helper to define the event.platform and sdkName
rxlabz Oct 23, 2020
4ff58a6
Merge remote-tracking branch 'origin/feat/sample-rate' into ref/trans…
rxlabz Oct 23, 2020
5493e19
fix
marandaneto Oct 23, 2020
621d6c4
update tests
rxlabz Oct 23, 2020
e11f653
Merge remote-tracking branch 'origin/feat/sample-rate' into ref/trans…
rxlabz Oct 23, 2020
88526e2
remove the platform arg from Client ctor
rxlabz Oct 23, 2020
796b633
set client.options private
rxlabz Oct 23, 2020
fb8b9e0
remove event.platform redefinition
rxlabz Oct 23, 2020
1dbcba4
set options.sdk if null
rxlabz Oct 23, 2020
8b56bce
remove fields from Transport Api
rxlabz Oct 23, 2020
daeb29e
private version consts
rxlabz Oct 23, 2020
098d58c
remove transport from the Client ctor
rxlabz Oct 23, 2020
2833a94
remove options.environmentAttributes
rxlabz Oct 23, 2020
35671d4
event processing : platform
rxlabz Oct 23, 2020
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
set client.options private
  • Loading branch information
rxlabz committed Oct 23, 2020
commit 796b633fbb4e776a3731d0e2dc6b90dbfb272e24
46 changes: 17 additions & 29 deletions dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,19 @@ abstract class SentryClient {
/// `dart:html` is available, otherwise it will throw an unsupported error.
factory SentryClient(SentryOptions options) => createSentryClient(options);

SentryClient.base(this.options, {String origin}) {
_random = options.sampleRate == null ? null : Random();
if (options.transport is NoOpTransport) {
options.transport = Transport(
options: options,
SentryClient.base(this._options, {String origin}) {
_random = _options.sampleRate == null ? null : Random();
if (_options.transport is NoOpTransport) {
_options.transport = Transport(
options: _options,
sdkIdentifier: '${sdkName}/${sdkVersion}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be replaced by options.sdkVersion.identifier? it looks duplicated now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ my bad, I thought sdkVersion was just a String, I renamed it sdk, and define it in the ioClient & BrowserClient if null

origin: origin,
);
}
}

@visibleForTesting
SentryOptions options;

/// Information about the current user.
///
/// This information is sent with every logged event. If the value
/// of this field is updated, all subsequent events will carry the
/// new information.
///
/// [Event.userContext] overrides the [User] context set here.
///
/// See also:
/// * https://docs.sentry.io/learn/context/#capturing-the-user
User userContext;
//@visibleForTesting
SentryOptions _options;

Random _random;

Expand All @@ -52,7 +40,7 @@ abstract class SentryClient {
Scope scope,
dynamic hint,
}) async {
event = _processEvent(event, eventProcessors: options.eventProcessors);
event = _processEvent(event, eventProcessors: _options.eventProcessors);

// dropped by sampling or event processors
if (event == null) {
Expand All @@ -63,7 +51,7 @@ abstract class SentryClient {

event = event.copyWith(platform: sdkPlatform);

return options.transport.send(event);
return _options.transport.send(event);
}

/// Reports the [throwable] and optionally its [stackTrace] to Sentry.io.
Expand All @@ -76,7 +64,7 @@ abstract class SentryClient {
final event = SentryEvent(
exception: throwable,
stackTrace: stackTrace,
timestamp: options.clock(),
timestamp: _options.clock(),
);
return captureEvent(event, scope: scope, hint: hint);
}
Expand All @@ -93,14 +81,14 @@ abstract class SentryClient {
final event = SentryEvent(
message: Message(formatted, template: template, params: params),
level: level,
timestamp: options.clock(),
timestamp: _options.clock(),
);

return captureEvent(event, scope: scope, hint: hint);
}

void close() {
options.httpClient?.close();
_options.httpClient?.close();
}

SentryEvent _processEvent(
Expand All @@ -109,7 +97,7 @@ abstract class SentryClient {
List<EventProcessor> eventProcessors,
}) {
if (_sampleRate()) {
options.logger(
_options.logger(
SentryLevel.debug,
'Event ${event.eventId.toString()} was dropped due to sampling decision.',
);
Expand All @@ -120,13 +108,13 @@ abstract class SentryClient {
try {
event = processor(event, hint);
} catch (err) {
options.logger(
_options.logger(
SentryLevel.error,
'An exception occurred while processing event by a processor : $err',
);
}
if (event == null) {
options.logger(SentryLevel.debug, 'Event was dropped by a processor');
_options.logger(SentryLevel.debug, 'Event was dropped by a processor');
break;
}
}
Expand Down Expand Up @@ -178,8 +166,8 @@ abstract class SentryClient {
}

bool _sampleRate() {
if (options.sampleRate != null && _random != null) {
return (options.sampleRate < _random.nextDouble());
if (_options.sampleRate != null && _random != null) {
return (_options.sampleRate < _random.nextDouble());
}
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ void main() {
test('captures event, sample rate is 100% enabled', () {
options.sampleRate = 1.0;
final client = SentryClient(options);
client.options.transport = transport;
options.transport = transport;
client.captureEvent(fakeEvent);

verify(client.options.transport.send(any)).called(1);
verify(transport.send(any)).called(1);
});

test('do not capture event, sample rate is 0% disabled', () {
options.sampleRate = 0.0;
final client = SentryClient(options);
client.options.transport = transport;
options.transport = transport;
client.captureEvent(fakeEvent);

verifyNever(client.options.transport.send(any));
verifyNever(transport.send(any));
});

test('captures event, sample rate is null, disabled', () {
options.sampleRate = null;
final client = SentryClient(options);
client.options.transport = transport;
options.transport = transport;
client.captureEvent(fakeEvent);

verify(client.options.transport.send(any)).called(1);
verify(transport.send(any)).called(1);
});
});
}
81 changes: 42 additions & 39 deletions dart/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,30 @@ Future testCaptureException(
fail('Unexpected request on ${request.method} ${request.url} in HttpMock');
});

var sentryId = SentryId.empty();
final client = SentryClient(
SentryOptions(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: compressPayload,
environmentAttributes: SentryEvent(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
timestamp: fakeClockProvider(),
),
final options = SentryOptions(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: compressPayload,
environmentAttributes: SentryEvent(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
timestamp: fakeClockProvider(),
),
);

var sentryId = SentryId.empty();
final client = SentryClient(options);

try {
throw ArgumentError('Test error');
} catch (error, stackTrace) {
sentryId = await client.captureException(error, stackTrace: stackTrace);
expect('$sentryId', 'testeventid');
}

expect(postUri, client.options.transport.dsn.postUri);
expect(postUri, options.transport.dsn.postUri);

testHeaders(
headers,
Expand Down Expand Up @@ -181,49 +181,53 @@ Future testCaptureException(

void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
test('can parse DSN', () async {
final client = SentryClient(SentryOptions(dsn: testDsn));
expect(client.options.transport.dsn.uri, Uri.parse(testDsn));
expect(client.options.transport.dsn.postUri,
final options = SentryOptions(dsn: testDsn);
final client = SentryClient(options);
expect(options.transport.dsn.uri, Uri.parse(testDsn));
expect(options.transport.dsn.postUri,
'https://sentry.example.com/api/1/store/');
expect(client.options.transport.dsn.publicKey, 'public');
expect(client.options.transport.dsn.secretKey, 'secret');
expect(client.options.transport.dsn.projectId, '1');
expect(options.transport.dsn.publicKey, 'public');
expect(options.transport.dsn.secretKey, 'secret');
expect(options.transport.dsn.projectId, '1');
await client.close();
});

test('can parse DSN without secret', () async {
final client = SentryClient(SentryOptions(dsn: _testDsnWithoutSecret));
expect(client.options.transport.dsn.uri, Uri.parse(_testDsnWithoutSecret));
expect(client.options.transport.dsn.postUri,
final options = SentryOptions(dsn: _testDsnWithoutSecret);
final client = SentryClient(options);
expect(options.transport.dsn.uri, Uri.parse(_testDsnWithoutSecret));
expect(options.transport.dsn.postUri,
'https://sentry.example.com/api/1/store/');
expect(client.options.transport.dsn.publicKey, 'public');
expect(client.options.transport.dsn.secretKey, null);
expect(client.options.transport.dsn.projectId, '1');
expect(options.transport.dsn.publicKey, 'public');
expect(options.transport.dsn.secretKey, null);
expect(options.transport.dsn.projectId, '1');
await client.close();
});

test('can parse DSN with path', () async {
final client = SentryClient(SentryOptions(dsn: _testDsnWithPath));
expect(client.options.transport.dsn.uri, Uri.parse(_testDsnWithPath));
final options = SentryOptions(dsn: _testDsnWithPath);
final client = SentryClient(options);
expect(options.transport.dsn.uri, Uri.parse(_testDsnWithPath));
expect(
client.options.transport.dsn.postUri,
options.transport.dsn.postUri,
'https://sentry.example.com/path/api/1/store/',
);
expect(client.options.transport.dsn.publicKey, 'public');
expect(client.options.transport.dsn.secretKey, 'secret');
expect(client.options.transport.dsn.projectId, '1');
expect(options.transport.dsn.publicKey, 'public');
expect(options.transport.dsn.secretKey, 'secret');
expect(options.transport.dsn.projectId, '1');
await client.close();
});
test('can parse DSN with port', () async {
final client = SentryClient(SentryOptions(dsn: _testDsnWithPort));
expect(client.options.transport.dsn.uri, Uri.parse(_testDsnWithPort));
final options = SentryOptions(dsn: _testDsnWithPort);
final client = SentryClient(options);
expect(options.transport.dsn.uri, Uri.parse(_testDsnWithPort));
expect(
client.options.transport.dsn.postUri,
options.transport.dsn.postUri,
'https://sentry.example.com:8888/api/1/store/',
);
expect(client.options.transport.dsn.publicKey, 'public');
expect(client.options.transport.dsn.secretKey, 'secret');
expect(client.options.transport.dsn.projectId, '1');
expect(options.transport.dsn.publicKey, 'public');
expect(options.transport.dsn.secretKey, 'secret');
expect(options.transport.dsn.projectId, '1');
await client.close();
});
test('sends client auth header without secret', () async {
Expand Down Expand Up @@ -367,7 +371,6 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
);

final client = SentryClient(options);
client.userContext = clientUserContext;

try {
throw ArgumentError('Test error');
Expand Down