File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ func simpleNetworkCallWithDelegate() {
5151}
5252
5353
54- let spanProcessor = SimpleSpanProcessor ( spanExporter: StdoutExporter ( isDebug: true ) )
54+ let spanProcessor = SimpleSpanProcessor ( spanExporter: StdoutSpanExporter ( isDebug: true ) )
5555OpenTelemetry . registerTracerProvider ( tracerProvider:
5656 TracerProviderBuilder ( )
5757 . add ( spanProcessor: spanProcessor)
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright The OpenTelemetry Authors
3+ * SPDX-License-Identifier: Apache-2.0
4+ */
5+
6+ import Foundation
7+ import OpenTelemetrySdk
8+
9+ class StdoutLogExporter : LogRecordExporter {
10+ let isDebug : Bool
11+
12+ init ( isDebug: Bool ) {
13+ self . isDebug = isDebug
14+ }
15+
16+ func export( logRecords: [ OpenTelemetrySdk . ReadableLogRecord ] , explicitTimeout: TimeInterval ? ) -> OpenTelemetrySdk . ExportResult {
17+ if isDebug {
18+ for logRecord in logRecords {
19+ print ( String ( repeating: " - " , count: 40 ) )
20+ print ( " Severity: \( String ( describing: logRecord. severity) ) " )
21+ print ( " Body: \( String ( describing: logRecord. body) ) " )
22+ print ( " InstrumentationScopeInfo: \( logRecord. instrumentationScopeInfo) " )
23+ print ( " Timestamp: \( logRecord. timestamp) " )
24+ print ( " ObservedTimestamp: \( String ( describing: logRecord. observedTimestamp) ) " )
25+ print ( " SpanContext: \( String ( describing: logRecord. spanContext) ) " )
26+ print ( " Resource: \( logRecord. resource. attributes) " )
27+ print ( " Attributes: \( logRecord. attributes) " )
28+ print ( String ( repeating: " - " , count: 40 ) + " \n " )
29+ }
30+ } else {
31+ do {
32+ let jsonData = try JSONEncoder ( ) . encode ( logRecords)
33+ if let jsonString = String ( data: jsonData, encoding: . utf8) {
34+ print ( jsonString)
35+ }
36+ } catch {
37+ print ( " Failed to serialize LogRecord as JSON: \( error) " )
38+ return . failure
39+ }
40+ }
41+ return . success
42+ }
43+
44+ func forceFlush( explicitTimeout: TimeInterval ? ) -> OpenTelemetrySdk . ExportResult {
45+ return . success
46+ }
47+
48+ func shutdown( explicitTimeout: TimeInterval ? ) { }
49+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,10 @@ import Foundation
77import OpenTelemetryApi
88import OpenTelemetrySdk
99
10- public class StdoutExporter : SpanExporter {
10+ @available ( * , deprecated, renamed: " StdoutSpanExporter " )
11+ public typealias StdoutExporter = StdoutSpanExporter
12+
13+ public class StdoutSpanExporter : SpanExporter {
1114 let isDebug : Bool
1215
1316 public init ( isDebug: Bool = false ) {
You can’t perform that action at this time.
0 commit comments