Skip to content
Draft
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## Unreleased

### Features

- Add Hint support to `beforeSendLog` and pass LogRecord from sentry_logging ([#3549](https://github.com/getsentry/sentry-dart/pull/3549))

### Breaking Changes

- `BeforeSendLogCallback` now takes `Hint` as a required positional parameter (matching `BeforeSendCallback` and `BeforeSendTransactionCallback`) ([#3549](https://github.com/getsentry/sentry-dart/pull/3549))

## 9.16.0

### Dependencies
Expand Down
3 changes: 2 additions & 1 deletion packages/dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class Hub {
return sentryId;
}

FutureOr<void> captureLog(SentryLog log) async {
FutureOr<void> captureLog(SentryLog log, {Hint? hint}) async {
if (!_isEnabled) {
_options.log(
SentryLevel.warning,
Expand All @@ -305,6 +305,7 @@ class Hub {
await item.client.captureLog(
log,
scope: scope,
hint: hint,
);
} catch (exception, stacktrace) {
_options.log(
Expand Down
3 changes: 2 additions & 1 deletion packages/dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ class HubAdapter implements Hub {
);

@override
FutureOr<void> captureLog(SentryLog log) => Sentry.currentHub.captureLog(log);
FutureOr<void> captureLog(SentryLog log, {Hint? hint}) =>
Sentry.currentHub.captureLog(log, hint: hint);

@override
Future<void> captureMetric(SentryMetric metric) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class NoOpHub implements Hub {
SentryId.empty();

@override
FutureOr<void> captureLog(SentryLog log) async {}
FutureOr<void> captureLog(SentryLog log, {Hint? hint}) async {}

@override
Future<void> captureMetric(SentryMetric metric) async {}
Expand Down
2 changes: 1 addition & 1 deletion packages/dart/lib/src/noop_sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NoOpSentryClient implements SentryClient {
SentryId.empty();

@override
FutureOr<void> captureLog(SentryLog log, {Scope? scope}) async {}
FutureOr<void> captureLog(SentryLog log, {Scope? scope, Hint? hint}) async {}

@override
Future<void> captureMetric(SentryMetric metric, {Scope? scope}) async {}
Expand Down
4 changes: 2 additions & 2 deletions packages/dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ class SentryClient {
}

@internal
FutureOr<void> captureLog(SentryLog log, {Scope? scope}) =>
_logCapturePipeline.captureLog(log, scope: scope);
FutureOr<void> captureLog(SentryLog log, {Scope? scope, Hint? hint}) =>
_logCapturePipeline.captureLog(log, scope: scope, hint: hint);

Future<void> captureMetric(SentryMetric metric, {Scope? scope}) =>
_metricCapturePipeline.captureMetric(metric, scope: scope);
Expand Down
5 changes: 4 additions & 1 deletion packages/dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ typedef BeforeBreadcrumbCallback = Breadcrumb? Function(

/// This function is called right before a log is about to be sent.
/// Can return a modified log or null to drop the log.
typedef BeforeSendLogCallback = FutureOr<SentryLog?> Function(SentryLog log);
typedef BeforeSendLogCallback = FutureOr<SentryLog?> Function(
SentryLog log,
Hint hint,
);

/// This function is called right before a metric is about to be emitted.
/// Can return true to emit the metric, or false to drop it.
Expand Down
54 changes: 40 additions & 14 deletions packages/dart/lib/src/telemetry/log/default_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import '../../../sentry.dart';
import '../../sentry_template_string.dart';
import '../../utils/internal_logger.dart';

typedef CaptureLogCallback = FutureOr<void> Function(SentryLog log);
typedef CaptureLogCallback = FutureOr<void> Function(SentryLog log,
{Hint? hint});
typedef ScopeProvider = Scope Function();

final class DefaultSentryLogger implements SentryLogger {
Expand All @@ -27,48 +28,60 @@ final class DefaultSentryLogger implements SentryLogger {
FutureOr<void> trace(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _captureLog(SentryLogLevel.trace, body, attributes: attributes);
return _captureLog(SentryLogLevel.trace, body,
attributes: attributes, hint: hint);
}

@override
FutureOr<void> debug(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _captureLog(SentryLogLevel.debug, body, attributes: attributes);
return _captureLog(SentryLogLevel.debug, body,
attributes: attributes, hint: hint);
}

@override
FutureOr<void> info(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _captureLog(SentryLogLevel.info, body, attributes: attributes);
return _captureLog(SentryLogLevel.info, body,
attributes: attributes, hint: hint);
}

@override
FutureOr<void> warn(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _captureLog(SentryLogLevel.warn, body, attributes: attributes);
return _captureLog(SentryLogLevel.warn, body,
attributes: attributes, hint: hint);
}

@override
FutureOr<void> error(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _captureLog(SentryLogLevel.error, body, attributes: attributes);
return _captureLog(SentryLogLevel.error, body,
attributes: attributes, hint: hint);
}

@override
FutureOr<void> fatal(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _captureLog(SentryLogLevel.fatal, body, attributes: attributes);
return _captureLog(SentryLogLevel.fatal, body,
attributes: attributes, hint: hint);
}

@override
Expand All @@ -80,6 +93,7 @@ final class DefaultSentryLogger implements SentryLogger {
SentryLogLevel level,
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
internalLogger.debug(() =>
'Sentry.logger.${level.value}("$body") called with attributes ${_formatAttributes(attributes)}');
Expand All @@ -93,7 +107,7 @@ final class DefaultSentryLogger implements SentryLogger {
attributes: attributes ?? {},
);

return _captureLogCallback(log);
return _captureLogCallback(log, hint: hint);
}

String _formatAttributes(Map<String, SentryAttribute>? attributes) {
Expand All @@ -112,13 +126,15 @@ final class _DefaultSentryLoggerFormatter implements SentryLoggerFormatter {
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _format(
templateBody,
arguments,
attributes,
(formattedBody, allAttributes) {
return _logger.trace(formattedBody, attributes: allAttributes);
return _logger.trace(formattedBody,
attributes: allAttributes, hint: hint);
},
);
}
Expand All @@ -128,13 +144,15 @@ final class _DefaultSentryLoggerFormatter implements SentryLoggerFormatter {
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _format(
templateBody,
arguments,
attributes,
(formattedBody, allAttributes) {
return _logger.debug(formattedBody, attributes: allAttributes);
return _logger.debug(formattedBody,
attributes: allAttributes, hint: hint);
},
);
}
Expand All @@ -144,13 +162,15 @@ final class _DefaultSentryLoggerFormatter implements SentryLoggerFormatter {
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _format(
templateBody,
arguments,
attributes,
(formattedBody, allAttributes) {
return _logger.info(formattedBody, attributes: allAttributes);
return _logger.info(formattedBody,
attributes: allAttributes, hint: hint);
},
);
}
Expand All @@ -160,13 +180,15 @@ final class _DefaultSentryLoggerFormatter implements SentryLoggerFormatter {
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _format(
templateBody,
arguments,
attributes,
(formattedBody, allAttributes) {
return _logger.warn(formattedBody, attributes: allAttributes);
return _logger.warn(formattedBody,
attributes: allAttributes, hint: hint);
},
);
}
Expand All @@ -176,13 +198,15 @@ final class _DefaultSentryLoggerFormatter implements SentryLoggerFormatter {
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _format(
templateBody,
arguments,
attributes,
(formattedBody, allAttributes) {
return _logger.error(formattedBody, attributes: allAttributes);
return _logger.error(formattedBody,
attributes: allAttributes, hint: hint);
},
);
}
Expand All @@ -192,13 +216,15 @@ final class _DefaultSentryLoggerFormatter implements SentryLoggerFormatter {
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
}) {
return _format(
templateBody,
arguments,
attributes,
(formattedBody, allAttributes) {
return _logger.fatal(formattedBody, attributes: allAttributes);
return _logger.fatal(formattedBody,
attributes: allAttributes, hint: hint);
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LogCapturePipeline {

LogCapturePipeline(this._options);

FutureOr<void> captureLog(SentryLog log, {Scope? scope}) async {
FutureOr<void> captureLog(SentryLog log, {Scope? scope, Hint? hint}) async {
if (!_options.enableLogs) {
internalLogger
.debug('$LogCapturePipeline: Logs disabled, dropping ${log.body}');
Expand All @@ -40,7 +40,7 @@ class LogCapturePipeline {
SentryLog? processedLog = log;
if (beforeSendLog != null) {
try {
final callbackResult = beforeSendLog(log);
final callbackResult = beforeSendLog(log, hint ?? Hint());

if (callbackResult is Future<SentryLog?>) {
processedLog = await callbackResult;
Expand Down
12 changes: 12 additions & 0 deletions packages/dart/lib/src/telemetry/log/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,42 @@ abstract interface class SentryLogger {
FutureOr<void> trace(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a message at DEBUG level.
FutureOr<void> debug(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a message at INFO level.
FutureOr<void> info(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a message at WARN level.
FutureOr<void> warn(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a message at ERROR level.
FutureOr<void> error(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a message at FATAL level.
FutureOr<void> fatal(
String body, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Provides formatted logging with template strings.
Expand All @@ -57,40 +63,46 @@ abstract interface class SentryLoggerFormatter {
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a formatted message at DEBUG level.
FutureOr<void> debug(
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a formatted message at INFO level.
FutureOr<void> info(
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a formatted message at WARN level.
FutureOr<void> warn(
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a formatted message at ERROR level.
FutureOr<void> error(
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});

/// Logs a formatted message at FATAL level.
FutureOr<void> fatal(
String templateBody,
List<dynamic> arguments, {
Map<String, SentryAttribute>? attributes,
Hint? hint,
});
}
Loading
Loading