|
1 | 1 | // Copyright 2021-2022 Workiva. |
2 | 2 | // Licensed under the Apache License, Version 2.0. Please see https://github.com/Workiva/opentelemetry-dart/blob/master/LICENSE for more information |
3 | 3 |
|
4 | | -import 'package:opentelemetry/api.dart' as api; |
5 | 4 | import 'package:opentelemetry/src/experimental_sdk.dart' as sdk; |
6 | 5 |
|
7 | 6 | /// This is implementation of [sdk.ReadWriteLogRecordExporter] that prints LogRecords to the |
@@ -29,34 +28,32 @@ class ConsoleLogRecordExporter implements sdk.LogRecordExporter { |
29 | 28 | /// converts logRecord info into more readable format |
30 | 29 | Map<String, dynamic> _makeObject(sdk.ReadableLogRecord log) { |
31 | 30 | final contextInfo = {}; |
32 | | - if (log.spanContext != null) { |
33 | | - contextInfo.addAll({ |
34 | | - 'traceId': log.spanContext!.traceId, |
35 | | - 'spanId': log.spanContext!.spanId, |
36 | | - 'traceFlags': log.spanContext!.traceFlags, |
37 | | - }); |
38 | | - } |
| 31 | + contextInfo.addAll({ |
| 32 | + 'traceId': log.spanContext.traceId, |
| 33 | + 'spanId': log.spanContext.spanId, |
| 34 | + 'traceFlags': log.spanContext.traceFlags, |
| 35 | + }); |
39 | 36 | return { |
40 | 37 | 'resource': { |
41 | 38 | 'attributes': { |
42 | | - for (final attribute in log.resource?.attributes.keys ?? <String>[]) |
43 | | - attribute: log.resource!.attributes.get(attribute), |
| 39 | + for (final attribute in log.resource.attributes.keys) |
| 40 | + attribute: log.resource.attributes.get(attribute), |
44 | 41 | }, |
45 | 42 | }, |
46 | 43 | 'instrumentationScope': { |
47 | | - 'name': log.instrumentationScope?.name, |
48 | | - 'version': log.instrumentationScope?.version, |
49 | | - 'schemaUrl': log.instrumentationScope?.schemaUrl, |
| 44 | + 'name': log.instrumentationScope.name, |
| 45 | + 'version': log.instrumentationScope.version, |
| 46 | + 'schemaUrl': log.instrumentationScope.schemaUrl, |
50 | 47 | 'attributes': { |
51 | | - for (final attribute in log.instrumentationScope?.attributes ?? <api.Attribute>[]) attribute.key: attribute.value, |
| 48 | + for (final attribute in log.instrumentationScope.attributes) attribute.key: attribute.value, |
52 | 49 | } |
53 | 50 | }, |
54 | 51 | 'timestamp': log.timeStamp, |
55 | 52 | 'severityText': log.severityText, |
56 | 53 | 'severityNumber': log.severityNumber, |
57 | 54 | 'body': log.body, |
58 | 55 | 'attributes': { |
59 | | - for (final attribute in log.attributes?.keys ?? <String>[]) attribute: log.resource!.attributes.get(attribute), |
| 56 | + for (final attribute in log.attributes.keys) attribute: log.resource.attributes.get(attribute), |
60 | 57 | }, |
61 | 58 | ...contextInfo, |
62 | 59 | }; |
|
0 commit comments