Line data Source code
1 : // Copyright The OpenTelemetry Authors
2 : // SPDX-License-Identifier: Apache-2.0
3 :
4 : import '../../dartastic_opentelemetry.dart' show OTelLog, Span;
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 : /// @param span The span to log
12 : /// @param message Optional message to include with the span log
13 1 : void logSpan(Span span, [String? message]) {
14 1 : if (OTelLog.logFunction != null) {
15 2 : final timestamp = DateTime.now().toIso8601String();
16 : final msg = message ?? '';
17 3 : OTelLog.logFunction!('[$timestamp] [message] $msg [span] $span');
18 : }
19 : }
20 :
21 : /// Logs multiple spans with an optional message.
22 : ///
23 : /// This utility function logs information about multiple spans for debugging purposes.
24 : /// It includes a timestamp and formats the spans information in a consistent way.
25 : ///
26 : /// @param spans The list of spans to log
27 : /// @param message Optional message to include with the spans log
28 38 : void logSpans(List<Span> spans, [String? message]) {
29 38 : if (OTelLog.isLogSpans()) {
30 76 : final timestamp = DateTime.now().toIso8601String();
31 : final msg = message ?? '';
32 76 : OTelLog.spanLogFunction!('[$timestamp] [message] $msg [spans] $spans');
33 : }
34 : }
|