Skip to content
2 changes: 1 addition & 1 deletion packages/dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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';
export 'src/telemetry/log/logger.dart';
export 'src/telemetry/metric/metrics.dart';
// ignore: invalid_export_of_internal_element
export 'src/utils/internal_logger.dart' show SentryInternalLogger;
37 changes: 0 additions & 37 deletions packages/dart/lib/src/logs_enricher_integration.dart

This file was deleted.

8 changes: 6 additions & 2 deletions packages/dart/lib/src/protocol/sentry_log.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'sentry_attribute.dart';
import 'sentry_id.dart';
import 'sentry_log_level.dart';
import 'span_id.dart';

class SentryLog {
DateTime timestamp;
SentryId traceId;
SpanId? spanId;
SentryLogLevel level;
String body;
Map<String, SentryAttribute> attributes;
Expand All @@ -14,17 +16,19 @@ class SentryLog {
/// by the time processing completes, it is guaranteed to be a valid non-empty trace id.
SentryLog({
required this.timestamp,
SentryId? traceId,
required this.traceId,
required this.level,
required this.body,
required this.attributes,
this.spanId,
this.severityNumber,
}) : traceId = traceId ?? SentryId.empty();
});

Map<String, dynamic> toJson() {
return {
'timestamp': timestamp.toIso8601String(),
'trace_id': traceId.toString(),
if (spanId != null) 'span_id': spanId.toString(),
'level': level.value,
'body': body,
'attributes':
Expand Down
4 changes: 2 additions & 2 deletions packages/dart/lib/src/sdk_lifecycle_hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class SdkLifecycleRegistry {
}

@internal
class OnBeforeCaptureLog extends SdkLifecycleEvent {
OnBeforeCaptureLog(this.log);
class OnProcessLog extends SdkLifecycleEvent {
OnProcessLog(this.log);

final SentryLog log;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import 'tracing.dart';
import 'transport/data_category.dart';
import 'transport/task_queue.dart';
import 'feature_flags_integration.dart';
import 'sentry_logger.dart';
import 'logs_enricher_integration.dart';
import 'telemetry/log/logger.dart';
import 'telemetry/log/logs_setup_integration.dart';

/// Configuration options callback
typedef OptionsConfiguration = FutureOr<void> Function(SentryOptions);
Expand Down Expand Up @@ -113,8 +113,8 @@ class Sentry {
}

options.addIntegration(MetricsSetupIntegration());
options.addIntegration(LogsSetupIntegration());
options.addIntegration(FeatureFlagsIntegration());
options.addIntegration(LogsEnricherIntegration());
options.addIntegration(InMemoryTelemetryProcessorIntegration());

options.addEventProcessor(EnricherEventProcessor(options));
Expand Down
107 changes: 12 additions & 95 deletions packages/dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'sentry_exception_factory.dart';
import 'sentry_options.dart';
import 'sentry_stack_trace_factory.dart';
import 'sentry_trace_context_header.dart';
import 'telemetry/log/log_capture_pipeline.dart';
import 'telemetry/metric/metric.dart';
import 'telemetry/metric/metric_capture_pipeline.dart';
import 'transport/client_report_transport.dart';
Expand All @@ -44,6 +45,7 @@ String get defaultIpAddress => _defaultIpAddress;
class SentryClient {
final SentryOptions _options;
final Random? _random;
final LogCapturePipeline _logCapturePipeline;
final MetricCapturePipeline _metricCapturePipeline;

static final _emptySentryId = Future.value(SentryId.empty());
Expand All @@ -53,7 +55,8 @@ class SentryClient {

/// Instantiates a client using [SentryOptions]
factory SentryClient(SentryOptions options,
{MetricCapturePipeline? metricCapturePipeline}) {
{LogCapturePipeline? logCapturePipeline,
MetricCapturePipeline? metricCapturePipeline}) {
if (options.sendClientReports) {
options.recorder = ClientReportRecorder(options.clock);
}
Expand All @@ -79,11 +82,15 @@ class SentryClient {
options.transport = SpotlightHttpTransport(options, options.transport);
}
return SentryClient._(
options, metricCapturePipeline ?? MetricCapturePipeline(options));
options,
logCapturePipeline ?? LogCapturePipeline(options),
metricCapturePipeline ?? MetricCapturePipeline(options),
);
}

/// Instantiates a client using [SentryOptions]
SentryClient._(this._options, this._metricCapturePipeline)
SentryClient._(
this._options, this._logCapturePipeline, this._metricCapturePipeline)
: _random = _options.sampleRate == null ? null : Random();

/// Reports an [event] to Sentry.io.
Expand Down Expand Up @@ -495,98 +502,8 @@ class SentryClient {
}

@internal
FutureOr<void> captureLog(
SentryLog log, {
Scope? scope,
}) async {
if (!_options.enableLogs) {
return;
}

if (scope != null) {
final merged = Map.of(scope.attributes)..addAll(log.attributes);
log.attributes = merged;
}

log.attributes['sentry.sdk.name'] = SentryAttribute.string(
_options.sdk.name,
);
log.attributes['sentry.sdk.version'] = SentryAttribute.string(
_options.sdk.version,
);
final environment = _options.environment;
if (environment != null) {
log.attributes['sentry.environment'] = SentryAttribute.string(
environment,
);
}
final release = _options.release;
if (release != null) {
log.attributes['sentry.release'] = SentryAttribute.string(
release,
);
}

final propagationContext = scope?.propagationContext;
if (propagationContext != null) {
log.traceId = propagationContext.traceId;
}
final span = scope?.span;
if (span != null) {
log.attributes['sentry.trace.parent_span_id'] = SentryAttribute.string(
span.context.spanId.toString(),
);
}

final user = scope?.user;
final id = user?.id;
final email = user?.email;
final name = user?.name;
if (id != null) {
log.attributes['user.id'] = SentryAttribute.string(id);
}
if (name != null) {
log.attributes['user.name'] = SentryAttribute.string(name);
}
if (email != null) {
log.attributes['user.email'] = SentryAttribute.string(email);
}

final beforeSendLog = _options.beforeSendLog;
SentryLog? processedLog = log;
if (beforeSendLog != null) {
try {
final callbackResult = beforeSendLog(log);

if (callbackResult is Future<SentryLog?>) {
processedLog = await callbackResult;
} else {
processedLog = callbackResult;
}
} catch (exception, stackTrace) {
_options.log(
SentryLevel.error,
'The beforeSendLog callback threw an exception',
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
}

if (processedLog != null) {
await _options.lifecycleRegistry
.dispatchCallback(OnBeforeCaptureLog(processedLog));
_options.telemetryProcessor.addLog(processedLog);
} else {
_options.recorder.recordLostEvent(
DiscardReason.beforeSend,
DataCategory.logItem,
);
}
}
FutureOr<void> captureLog(SentryLog log, {Scope? scope}) =>
_logCapturePipeline.captureLog(log, scope: scope);

Future<void> captureMetric(SentryMetric metric, {Scope? scope}) =>
_metricCapturePipeline.captureMetric(metric, scope: scope);
Expand Down
95 changes: 0 additions & 95 deletions packages/dart/lib/src/sentry_logger.dart

This file was deleted.

Loading
Loading