Skip to content
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
38 changes: 19 additions & 19 deletions lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ class SentryClient {
'sentry_secret=$secretKey',
};

final Map<String, dynamic> json = <String, dynamic>{
final Map<String, dynamic> outputBodyJson = <String, dynamic>{
'project': projectId,
'event_id': _uuidGenerator(),
'timestamp': formatDateAsIso8601WithSecondPrecision(_clock.now()),
'logger': defaultLoggerName,
};

if (environmentAttributes != null)
mergeAttributes(environmentAttributes.toJson(), into: json);
mergeAttributes(environmentAttributes.toJson(), into: outputBodyJson);

mergeAttributes(event.toJson(), into: json);
mergeAttributes(event.toJson(), into: outputBodyJson);

List<int> body = UTF8.encode(JSON.encode(json));
List<int> body = utf8.encode(json.encode(outputBodyJson));
if (compressPayload) {
headers['Content-Encoding'] = 'gzip';
body = GZIP.encode(body);
Expand All @@ -190,7 +190,7 @@ class SentryClient {
return new SentryResponse.failure(errorMessage);
}

final String eventId = JSON.decode(response.body)['id'];
final String eventId = json.decode(response.body)['id'];
return new SentryResponse.success(eventId: eventId);
}

Expand Down Expand Up @@ -349,26 +349,26 @@ class Event {

/// Serializes this event to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> json = <String, dynamic>{
final Map<String, dynamic> eventJson = <String, dynamic>{
'platform': sdkPlatform,
'sdk': {
'version': sdkVersion,
'name': sdkName,
},
};

if (loggerName != null) json['logger'] = loggerName;
if (loggerName != null) eventJson['logger'] = loggerName;

if (serverName != null) json['server_name'] = serverName;
if (serverName != null) eventJson['server_name'] = serverName;

if (release != null) json['release'] = release;
if (release != null) eventJson['release'] = release;

if (environment != null) json['environment'] = environment;
if (environment != null) eventJson['environment'] = environment;

if (message != null) json['message'] = message;
if (message != null) eventJson['message'] = message;

if (exception != null) {
json['exception'] = [
eventJson['exception'] = [
<String, dynamic>{
'type': '${exception.runtimeType}',
'value': '$exception',
Expand All @@ -377,22 +377,22 @@ class Event {
}

if (stackTrace != null) {
json['stacktrace'] = <String, dynamic>{
eventJson['stacktrace'] = <String, dynamic>{
'frames': encodeStackTrace(stackTrace),
};
}

if (level != null) json['level'] = level.name;
if (level != null) eventJson['level'] = level.name;

if (culprit != null) json['culprit'] = culprit;
if (culprit != null) eventJson['culprit'] = culprit;

if (tags != null && tags.isNotEmpty) json['tags'] = tags;
if (tags != null && tags.isNotEmpty) eventJson['tags'] = tags;

if (extra != null && extra.isNotEmpty) json['extra'] = extra;
if (extra != null && extra.isNotEmpty) eventJson['extra'] = extra;

if (fingerprint != null && fingerprint.isNotEmpty)
json['fingerprint'] = fingerprint;
eventJson['fingerprint'] = fingerprint;

return json;
return eventJson;
}
}
10 changes: 5 additions & 5 deletions test/sentry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ void main() {

expect(headers, expectedHeaders);

Map<String, dynamic> json;
Map<String, dynamic> bodyJson;
if (compressPayload) {
json = JSON.decode(UTF8.decode(GZIP.decode(body)));
bodyJson = json.decode(utf8.decode(GZIP.decode(body)));
} else {
json = JSON.decode(UTF8.decode(body));
bodyJson = json.decode(utf8.decode(body));
}
final Map<String, dynamic> stacktrace = json.remove('stacktrace');
final Map<String, dynamic> stacktrace = bodyJson.remove('stacktrace');
expect(stacktrace['frames'], const isInstanceOf<List>());
expect(stacktrace['frames'], isNotEmpty);

Expand All @@ -98,7 +98,7 @@ void main() {
expect(topFrame['in_app'], true);
expect(topFrame['filename'], 'sentry_test.dart');

expect(json, {
expect(bodyJson, {
'project': '1',
'event_id': 'X' * 32,
'timestamp': '2017-01-02T00:00:00',
Expand Down