Line data Source code
1 : // Licensed under the Apache License, Version 2.0
2 : // Copyright 2025, Michael Bushe, All rights reserved.
3 :
4 : import '../../dartastic_opentelemetry.dart' show Span, OTelLog;
5 :
6 : /// Logs a single span with an optional message.
7 : ///
8 : /// This utility function logs span information for debugging purposes.
9 : /// It includes a timestamp and formats the span information in a consistent way.
10 : ///
11 : /// Note: Per [OTEP 0265](https://opentelemetry.io/docs/specs/semconv/general/events/),
12 : /// span events are being deprecated and will be replaced by the Logging API in future versions.
13 : ///
14 : /// @param span The span to log
15 : /// @param message Optional message to include with the span log
16 1 : void logSpan(Span span, [String? message]) {
17 1 : if (OTelLog.logFunction != null) {
18 2 : final timestamp = DateTime.now().toIso8601String();
19 : final String msg = message ?? '';
20 3 : OTelLog.logFunction!('[$timestamp] [message] $msg [span] $span');
21 : }
22 : }
23 :
24 : /// Logs multiple spans with an optional message.
25 : ///
26 : /// This utility function logs information about multiple spans for debugging purposes.
27 : /// It includes a timestamp and formats the spans information in a consistent way.
28 : ///
29 : /// Note: Per [OTEP 0265](https://opentelemetry.io/docs/specs/semconv/general/events/),
30 : /// span events are being deprecated and will be replaced by the Logging API in future versions.
31 : ///
32 : /// @param spans The list of spans to log
33 : /// @param message Optional message to include with the spans log
34 17 : void logSpans(List<Span> spans, [String? message]) {
35 17 : if (OTelLog.isLogSpans()) {
36 34 : final timestamp = DateTime.now().toIso8601String();
37 : final String msg = message ?? '';
38 34 : OTelLog.spanLogFunction!('[$timestamp] [message] $msg [spans] $spans');
39 : }
40 : }
|