Skip to content

Sentry Structured Logs #2919

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

Merged
merged 8 commits into from
May 20, 2025
Merged
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

## Unreleased

### Features

- Sentry Structured Logs ([#2919](https://github.com/getsentry/sentry-dart/pull/2919))
- The old `SentryLogger` has been renamed to `SdkLogCallback` and can be accessed through `options.log` now.
- Adds support for structured logging though `Sentry.logger`:
```dart
// Enable in `SentryOptions`:
options.enableLogs = true;

// Use `Sentry.logger`
Sentry.logger.info("This is a info log.");
Sentry.logger.warn("This is a warning log with attributes.", attributes: {
'string-attribute': SentryLogAttribute.string('string'),
'int-attribute': SentryLogAttribute.int(1),
'double-attribute': SentryLogAttribute.double(1.0),
'bool-attribute': SentryLogAttribute.bool(true),
});
```

### Enhancements

- Align User Feedback API ([#2949](https://github.com/getsentry/sentry-dart/pull/2949))
Expand Down
1 change: 1 addition & 0 deletions dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ export 'src/utils/tracing_utils.dart';
export 'src/utils/url_details.dart';
// ignore: invalid_export_of_internal_element
export 'src/utils/breadcrumb_log_level.dart';
export 'src/sentry_logger.dart';
2 changes: 2 additions & 0 deletions dart/lib/src/client_reports/discarded_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
return 'security';
case DataCategory.unknown:
return 'unknown';
case DataCategory.logItem:

Check warning on line 67 in dart/lib/src/client_reports/discarded_event.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/client_reports/discarded_event.dart#L67

Added line #L67 was not covered by tests
return 'log_item';
case DataCategory.feedback:
return 'feedback';
case DataCategory.metricBucket:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'protocol.dart';
import 'sentry_options.dart';

class DiagnosticLogger {
class DiagnosticLog {
final SentryOptions _options;
final SentryLogger _logger;
SentryLogger get logger => _logger;
final SdkLogCallback _logger;
SdkLogCallback get logger => _logger;

DiagnosticLogger(this._logger, this._options);
DiagnosticLog(this._logger, this._options);

void log(
SentryLevel level,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DeduplicationEventProcessor implements EventProcessor {
}

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

if (_exceptionToDeduplicate.contains(exceptionHashCode)) {
_options.logger(
_options.log(
SentryLevel.info,
'Duplicated exception detected. '
'Event ${event.eventId} will be discarded.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
return result.stdout.toString();
}
} catch (e) {
options.logger(SentryLevel.warning, "Failed to run process: $e");
options.log(SentryLevel.warning, "Failed to run process: $e");

Check warning on line 90 in dart/lib/src/event_processor/enricher/io_platform_memory.dart

View check run for this annotation

Codecov / codecov/patch

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

Added line #L90 was not covered by tests
if (options.automatedTestMode) {
rethrow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
var uri = Uri.parse(address.host);
request = SentryRequest.fromUri(uri: uri);
} catch (exception, stackTrace) {
_options.logger(
_options.log(

Check warning on line 74 in dart/lib/src/event_processor/exception/io_exception_event_processor.dart

View check run for this annotation

Codecov / codecov/patch

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

Added line #L74 was not covered by tests
SentryLevel.error,
'Could not parse ${address.host} to Uri',
exception: exception,
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/event_processor/run_event_processors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
final e = processor.apply(processedEvent!, hint);
processedEvent = e is Future<SentryEvent?> ? await e : e;
} catch (exception, stackTrace) {
options.logger(
options.log(

Check warning on line 28 in dart/lib/src/event_processor/run_event_processors.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/event_processor/run_event_processors.dart#L28

Added line #L28 was not covered by tests
SentryLevel.error,
'An exception occurred while processing event by a processor',
exception: exception,
Expand All @@ -47,7 +47,7 @@
count: spanCountBeforeEventProcessors + 1,
);
}
options.logger(SentryLevel.debug, 'Event was dropped by a processor');
options.log(SentryLevel.debug, 'Event was dropped by a processor');
break;
} else if (event is SentryTransaction &&
processedEvent is SentryTransaction) {
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/http_client/io_client_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class IoClientProvider implements ClientProvider {
}
final pac = proxy.toPacString();
if (proxy.type == SentryProxyType.socks) {
options.logger(
options.log(
SentryLevel.warning,
"Setting proxy '$pac' is not supported.",
);
return Client();
}
options.logger(
options.log(
SentryLevel.info,
"Setting proxy '$pac'",
);
Expand Down
Loading
Loading