Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds StdoutLogExporter to match (renamed) StdoutSpanExporter #559

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/Network Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func simpleNetworkCallWithDelegate() {
}


let spanProcessor = SimpleSpanProcessor(spanExporter: StdoutExporter(isDebug: true))
let spanProcessor = SimpleSpanProcessor(spanExporter: StdoutSpanExporter(isDebug: true))
OpenTelemetry.registerTracerProvider(tracerProvider:
TracerProviderBuilder()
.add(spanProcessor: spanProcessor)
Expand Down
49 changes: 49 additions & 0 deletions Sources/Exporters/Stdout/StdoutLogExporter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import Foundation
import OpenTelemetrySdk

class StdoutLogExporter: LogRecordExporter {
let isDebug: Bool

init(isDebug: Bool) {
self.isDebug = isDebug
}

func export(logRecords: [OpenTelemetrySdk.ReadableLogRecord], explicitTimeout: TimeInterval?) -> OpenTelemetrySdk.ExportResult {
if isDebug {
for logRecord in logRecords {
print(String(repeating: "-", count: 40))
print("Severity: \(String(describing: logRecord.severity))")
print("Body: \(String(describing: logRecord.body))")
print("InstrumentationScopeInfo: \(logRecord.instrumentationScopeInfo)")
print("Timestamp: \(logRecord.timestamp)")
print("ObservedTimestamp: \(String(describing: logRecord.observedTimestamp))")
print("SpanContext: \(String(describing: logRecord.spanContext))")
print("Resource: \(logRecord.resource.attributes)")
print("Attributes: \(logRecord.attributes)")
print(String(repeating: "-", count: 40) + "\n")
}
} else {
do {
let jsonData = try JSONEncoder().encode(logRecords)
if let jsonString = String(data: jsonData, encoding: .utf8) {
print(jsonString)
}
} catch {
print("Failed to serialize LogRecord as JSON: \(error)")
return .failure
}
}
return .success
}

func forceFlush(explicitTimeout: TimeInterval?) -> OpenTelemetrySdk.ExportResult {
return .success
}

func shutdown(explicitTimeout: TimeInterval?) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import Foundation
import OpenTelemetryApi
import OpenTelemetrySdk

public class StdoutExporter: SpanExporter {
@available(*, deprecated, renamed: "StdoutSpanExporter")
public typealias StdoutExporter=StdoutSpanExporter

public class StdoutSpanExporter: SpanExporter {
let isDebug: Bool

public init(isDebug: Bool = false) {
Expand Down
Loading