Skip to content

Commit ed37be9

Browse files
authored
Use feedback handler instead of print() (#1040)
1 parent 3bb459f commit ed37be9

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

Sources/Exporters/OpenTelemetryProtocolGrpc/trace/OtlpTraceJsonExporter.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import Foundation
7+
import OpenTelemetryApi
78
import OpenTelemetrySdk
89
import OpenTelemetryProtocolExporterCommon
910

@@ -32,7 +33,7 @@ public class OtlpTraceJsonExporter: SpanExporter {
3233
let span = try JSONDecoder().decode(OtlpSpan.self, from: jsonData)
3334
exportedSpans.append(span)
3435
} catch {
35-
print("Decode Error: \(error)")
36+
OpenTelemetry.instance.feedbackHandler?("Decode Error: \(error)")
3637
}
3738
return .success
3839
} catch {

Sources/Exporters/Prometheus/PrometheusExporterHttpServer.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Foundation
77
import NIO
88
import NIOHTTP1
9+
import OpenTelemetryApi
910

1011
public class PrometheusExporterHttpServer {
1112
private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
@@ -24,7 +25,7 @@ public class PrometheusExporterHttpServer {
2425
public func start() throws {
2526
do {
2627
let channel = try serverBootstrap.bind(host: host, port: port).wait()
27-
print("Listening on \(String(describing: channel.localAddress))...")
28+
OpenTelemetry.instance.feedbackHandler?("Listening on \(String(describing: channel.localAddress))...")
2829
try channel.closeFuture.wait()
2930
} catch {
3031
throw error
@@ -35,10 +36,10 @@ public class PrometheusExporterHttpServer {
3536
do {
3637
try group.syncShutdownGracefully()
3738
} catch {
38-
print("Error shutting down \(error.localizedDescription)")
39+
OpenTelemetry.instance.feedbackHandler?("Error shutting down \(error.localizedDescription)")
3940
exit(0)
4041
}
41-
print("Client connection closed")
42+
OpenTelemetry.instance.feedbackHandler?("Client connection closed")
4243
}
4344

4445
private var serverBootstrap: ServerBootstrap {
@@ -108,7 +109,7 @@ public class PrometheusExporterHttpServer {
108109
}
109110

110111
public func errorCaught(context: ChannelHandlerContext, error: Error) {
111-
print("error: ", error)
112+
OpenTelemetry.instance.feedbackHandler?("error: \(error)")
112113

113114
// As we are not really interested getting notified on success or failure we just pass nil as promise to
114115
// reduce allocations.

Sources/Instrumentation/SDKResourceExtension/DataSource/DeviceDataSource.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import Foundation
7+
import OpenTelemetryApi
78
#if os(watchOS)
89
import WatchKit
910
#elseif os(macOS)
@@ -47,7 +48,7 @@ public class DeviceDataSource: IDeviceDataSource {
4748
let modelRequestError = sysctl(hwName, 2, machine, len, nil, 0)
4849
if modelRequestError != 0 {
4950
// TODO: better error log
50-
print("error #\(errno): \(String(describing: String(utf8String: strerror(errno))))")
51+
OpenTelemetry.instance.feedbackHandler?("error #\(errno): \(String(describing: String(utf8String: strerror(errno))))")
5152

5253
return nil
5354
}

Sources/Instrumentation/URLSession/URLSessionInstrumentation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public class URLSessionInstrumentation {
170170
].forEach {
171171
let selector = $0
172172
guard let original = class_getInstanceMethod(cls, selector) else {
173-
print("injectInto \(selector.description) failed")
173+
OpenTelemetry.instance.feedbackHandler?("injectInto \(selector.description) failed")
174174
return
175175
}
176176
var originalIMP: IMP?
@@ -295,7 +295,7 @@ public class URLSessionInstrumentation {
295295
].forEach {
296296
let selector = $0
297297
guard let original = class_getInstanceMethod(cls, selector) else {
298-
print("injectInto \(selector.description) failed")
298+
OpenTelemetry.instance.feedbackHandler?("injectInto \(selector.description) failed")
299299
return
300300
}
301301
var originalIMP: IMP?
@@ -385,7 +385,7 @@ public class URLSessionInstrumentation {
385385
].forEach {
386386
let selector = $0
387387
guard let original = class_getInstanceMethod(cls, selector) else {
388-
print("injectInto \(selector.description) failed")
388+
OpenTelemetry.instance.feedbackHandler?("injectInto \(selector.description) failed")
389389
return
390390
}
391391
var originalIMP: IMP?

0 commit comments

Comments
 (0)