Line data Source code
1 : // Copyright The OpenTelemetry Authors
2 : // SPDX-License-Identifier: Apache-2.0
3 :
4 : import 'package:dartastic_opentelemetry_api/dartastic_opentelemetry_api.dart';
5 :
6 : import 'readable_log_record.dart';
7 :
8 : /// Interface for log record processors that handle log record lifecycle events.
9 : ///
10 : /// Log record processors are invoked when a log record is emitted. They are
11 : /// responsible for performing additional processing on log records, such as
12 : /// filtering, batching, or exporting them.
13 : ///
14 : /// More information:
15 : /// https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor
16 : abstract class LogRecordProcessor {
17 : /// Called when a log record is emitted.
18 : ///
19 : /// This method is called synchronously when a log record is emitted, allowing
20 : /// for immediate processing of the log record. Implementations should be
21 : /// lightweight and avoid blocking operations or excessive processing.
22 : ///
23 : /// The logRecord parameter is a ReadWriteLogRecord, allowing processors
24 : /// to modify the log record. Mutations are visible in subsequent processors.
25 : ///
26 : /// @param logRecord The log record that was emitted (ReadWriteLogRecord)
27 : /// @param context The context associated with the log record
28 : Future<void> onEmit(ReadWriteLogRecord logRecord, Context? context);
29 :
30 : /// Called to determine if the logger is enabled for a given configuration.
31 : ///
32 : /// This method supports filtering via OTelLogger.enabled. It helps optimize
33 : /// performance by allowing early filtering of log records.
34 : ///
35 : /// @param context The context (explicit or current)
36 : /// @param instrumentationScope The instrumentation scope
37 : /// @param severityNumber The severity number of the potential log
38 : /// @param eventName The event name, if any
39 : /// @return false if the log record should be filtered out, true otherwise
40 0 : bool enabled({
41 : Context? context,
42 : InstrumentationScope? instrumentationScope,
43 : Severity? severityNumber,
44 : String? eventName,
45 : }) {
46 : // Default implementation returns true (indeterminate state)
47 : return true;
48 : }
49 :
50 : /// Shuts down the log record processor.
51 : ///
52 : /// This method is called when the logger provider is shut down.
53 : /// Implementations should release any resources they hold and perform
54 : /// any final processing of log records.
55 : Future<void> shutdown();
56 :
57 : /// Forces the log record processor to flush any queued log records.
58 : ///
59 : /// This method is called when the logger provider's forceFlush method
60 : /// is called. Implementations should ensure that any log records that have
61 : /// been processed but not yet exported are exported immediately.
62 : Future<void> forceFlush();
63 : }
|