Skip to content

Commit 9ef5d50

Browse files
denrasebuenaflor
andauthored
Sentry Structured Logs (#2919)
* Logs: Models & Envelopes (#2916) * Logs: Integrate in Sentry Client (#2920) * [Structured Logs]: Expose Public API (#2940) * update changelog entry --------- Co-authored-by: Giancarlo Buenaflor <[email protected]>
1 parent 436a1fc commit 9ef5d50

File tree

111 files changed

+1511
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1511
-253
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Sentry Structured Logs ([#2919](https://github.com/getsentry/sentry-dart/pull/2919))
8+
- The old `SentryLogger` has been renamed to `SdkLogCallback` and can be accessed through `options.log` now.
9+
- Adds support for structured logging though `Sentry.logger`:
10+
```dart
11+
// Enable in `SentryOptions`:
12+
options.enableLogs = true;
13+
14+
// Use `Sentry.logger`
15+
Sentry.logger.info("This is a info log.");
16+
Sentry.logger.warn("This is a warning log with attributes.", attributes: {
17+
'string-attribute': SentryLogAttribute.string('string'),
18+
'int-attribute': SentryLogAttribute.int(1),
19+
'double-attribute': SentryLogAttribute.double(1.0),
20+
'bool-attribute': SentryLogAttribute.bool(true),
21+
});
22+
```
23+
524
### Enhancements
625

726
- Align User Feedback API ([#2949](https://github.com/getsentry/sentry-dart/pull/2949))

dart/lib/sentry.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ export 'src/utils/tracing_utils.dart';
6060
export 'src/utils/url_details.dart';
6161
// ignore: invalid_export_of_internal_element
6262
export 'src/utils/breadcrumb_log_level.dart';
63+
export 'src/sentry_logger.dart';

dart/lib/src/client_reports/discarded_event.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ extension _DataCategoryExtension on DataCategory {
6464
return 'security';
6565
case DataCategory.unknown:
6666
return 'unknown';
67+
case DataCategory.logItem:
68+
return 'log_item';
6769
case DataCategory.feedback:
6870
return 'feedback';
6971
case DataCategory.metricBucket:

dart/lib/src/diagnostic_logger.dart renamed to dart/lib/src/diagnostic_log.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import 'protocol.dart';
22
import 'sentry_options.dart';
33

4-
class DiagnosticLogger {
4+
class DiagnosticLog {
55
final SentryOptions _options;
6-
final SentryLogger _logger;
7-
SentryLogger get logger => _logger;
6+
final SdkLogCallback _logger;
7+
SdkLogCallback get logger => _logger;
88

9-
DiagnosticLogger(this._logger, this._options);
9+
DiagnosticLog(this._logger, this._options);
1010

1111
void log(
1212
SentryLevel level,

dart/lib/src/event_processor/deduplication_event_processor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DeduplicationEventProcessor implements EventProcessor {
3232
}
3333

3434
if (!_options.enableDeduplication) {
35-
_options.logger(SentryLevel.debug, 'Deduplication is disabled');
35+
_options.log(SentryLevel.debug, 'Deduplication is disabled');
3636
return event;
3737
}
3838
return _deduplicate(event);
@@ -52,7 +52,7 @@ class DeduplicationEventProcessor implements EventProcessor {
5252
final exceptionHashCode = exception.hashCode;
5353

5454
if (_exceptionToDeduplicate.contains(exceptionHashCode)) {
55-
_options.logger(
55+
_options.log(
5656
SentryLevel.info,
5757
'Duplicated exception detected. '
5858
'Event ${event.eventId} will be discarded.',

dart/lib/src/event_processor/enricher/io_platform_memory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class PlatformMemory {
8787
return result.stdout.toString();
8888
}
8989
} catch (e) {
90-
options.logger(SentryLevel.warning, "Failed to run process: $e");
90+
options.log(SentryLevel.warning, "Failed to run process: $e");
9191
if (options.automatedTestMode) {
9292
rethrow;
9393
}

dart/lib/src/event_processor/exception/io_exception_event_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class IoExceptionEventProcessor implements ExceptionEventProcessor {
7171
var uri = Uri.parse(address.host);
7272
request = SentryRequest.fromUri(uri: uri);
7373
} catch (exception, stackTrace) {
74-
_options.logger(
74+
_options.log(
7575
SentryLevel.error,
7676
'Could not parse ${address.host} to Uri',
7777
exception: exception,

dart/lib/src/event_processor/run_event_processors.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Future<SentryEvent?> runEventProcessors(
2525
final e = processor.apply(processedEvent!, hint);
2626
processedEvent = e is Future<SentryEvent?> ? await e : e;
2727
} catch (exception, stackTrace) {
28-
options.logger(
28+
options.log(
2929
SentryLevel.error,
3030
'An exception occurred while processing event by a processor',
3131
exception: exception,
@@ -47,7 +47,7 @@ Future<SentryEvent?> runEventProcessors(
4747
count: spanCountBeforeEventProcessors + 1,
4848
);
4949
}
50-
options.logger(SentryLevel.debug, 'Event was dropped by a processor');
50+
options.log(SentryLevel.debug, 'Event was dropped by a processor');
5151
break;
5252
} else if (event is SentryTransaction &&
5353
processedEvent is SentryTransaction) {

dart/lib/src/http_client/io_client_provider.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class IoClientProvider implements ClientProvider {
3636
}
3737
final pac = proxy.toPacString();
3838
if (proxy.type == SentryProxyType.socks) {
39-
options.logger(
39+
options.log(
4040
SentryLevel.warning,
4141
"Setting proxy '$pac' is not supported.",
4242
);
4343
return Client();
4444
}
45-
options.logger(
45+
options.log(
4646
SentryLevel.info,
4747
"Setting proxy '$pac'",
4848
);

0 commit comments

Comments
 (0)