Skip to content

Commit

Permalink
set sent_at in http_transport
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed May 9, 2023
1 parent fdcec41 commit a606145
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
11 changes: 4 additions & 7 deletions dart/lib/src/transport/http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class HttpTransport implements Transport {
if (filteredEnvelope == null) {
return SentryId.empty();
}
filteredEnvelope.header.sentAt = _options.clock();

final streamedRequest = await _createStreamedRequest(filteredEnvelope);
final response = await _options.httpClient
Expand Down Expand Up @@ -134,11 +135,9 @@ class HttpTransport implements Transport {
class _CredentialBuilder {
final String _authHeader;

_CredentialBuilder._(String authHeader)
: _authHeader = authHeader;
_CredentialBuilder._(String authHeader) : _authHeader = authHeader;

factory _CredentialBuilder(
Dsn dsn, String sdkIdentifier) {
factory _CredentialBuilder(Dsn dsn, String sdkIdentifier) {
final authHeader = _buildAuthHeader(
publicKey: dsn.publicKey,
secretKey: dsn.secretKey,
Expand Down Expand Up @@ -166,9 +165,7 @@ class _CredentialBuilder {
Map<String, String> configure(Map<String, String> headers) {
return headers
..addAll(
<String, String>{
'X-Sentry-Auth': _authHeader
},
<String, String>{'X-Sentry-Auth': _authHeader},
);
}
}
Expand Down
28 changes: 28 additions & 0 deletions dart/test/transport/http_transport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ void main() {
});
});

group('sent_at', () {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

test('capture envelope sets sent_at in header', () async {
final sentryEvent = SentryEvent();
final envelope = SentryEnvelope.fromEvent(
sentryEvent,
fixture.options.sdk,
dsn: fixture.options.dsn,
);

final httpMock = MockClient((http.Request request) async {
return http.Response('{}', 200);
});
final sut = fixture.getSut(httpMock, MockRateLimiter());
await sut.send(envelope);

expect(envelope.header.sentAt, DateTime.utc(2019));
});
});

group('client reports', () {
late Fixture fixture;

Expand Down Expand Up @@ -232,6 +257,9 @@ class Fixture {
HttpTransport getSut(http.Client client, RateLimiter rateLimiter) {
options.httpClient = client;
options.recorder = clientReportRecorder;
options.clock = () {
return DateTime.utc(2019);
};
return HttpTransport(options, rateLimiter);
}
}

0 comments on commit a606145

Please sign in to comment.