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

Merge meta dictionary to root of body #1

Closed
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/src/insightops_dart_base.dart
Expand Up @@ -93,11 +93,13 @@ class InsightOpsLogger {
if (record.error != null) {
body['error'] = record.error.toString();
}

final meta = await _getMeta();
if (meta?.isNotEmpty == true) {
body['meta'] = meta;
}
return body;
assert((meta?.isEmpty ?? true) ||
body.keys.toSet().intersection(meta.keys.toSet()).isEmpty);
meta?.removeWhere((key, _) => body.containsKey(key));

return {...body, ...?meta};
}

Duration _currentTimeout = _initialTimeout;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: insightops_dart
description: Unofficial wrapper for using Rapid7 insightOps logs (former LogEntries) with Dart.
version: 0.0.6
version: 0.1.0
homepage: https://github.com/ookami-kb/insightops_dart
author: Kirill Bubochkin <ookami.kb@gmail.com>

Expand Down
6 changes: 5 additions & 1 deletion test/insightops_dart_test.dart
Expand Up @@ -39,14 +39,18 @@ void main() {
Logger.root.onRecord.listen(InsightOpsLogger(
_url,
post: testPostHandler,
getMeta: () async => {'deviceId': 'ID'},
getMeta: () async => {
'meta': {'deviceId': 'ID'},
'module': 'flutter'
},
));

logger.info('message');

await Future.delayed(Duration(seconds: 1));

expect(json.decode(sentMessages.first)['meta']['deviceId'], 'ID');
expect(json.decode(sentMessages.first)['module'], 'flutter');
});

test('retries after timeout on error', () async {
Expand Down