Skip to content

Commit 09b6529

Browse files
committed
ensure that call option timeout is included in export calls
1 parent ec42fcd commit 09b6529

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

Package.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ let package = Package(
3434
.executable(name: "loggingTracer", targets: ["LoggingTracer"]),
3535
],
3636
dependencies: [
37-
.package(name: "Opentracing", url: "https://github.com/undefinedlabs/opentracing-objc", from: "0.5.2"),
38-
.package(name: "Thrift", url: "https://github.com/undefinedlabs/Thrift-Swift", from: "1.1.1"),
39-
.package(name: "swift-nio", url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
40-
.package(name: "grpc-swift", url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
41-
.package(name: "swift-protobuf", url: "https://github.com/apple/swift-protobuf.git", from: "1.20.2"),
42-
.package(name: "swift-log", url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
43-
.package(name: "swift-metrics", url: "https://github.com/apple/swift-metrics.git", from: "2.1.1"),
44-
.package(name: "Reachability.swift", url: "https://github.com/ashleymills/Reachability.swift", from: "5.1.0")
37+
.package(name: "Opentracing", url: "https://github.com/undefinedlabs/opentracing-objc", exact: "0.5.2"),
38+
.package(name: "Thrift", url: "https://github.com/undefinedlabs/Thrift-Swift", exact: "1.1.1"),
39+
.package(name: "swift-nio", url: "https://github.com/apple/swift-nio.git", exact: "2.0.0"),
40+
.package(name: "grpc-swift", url: "https://github.com/grpc/grpc-swift.git", exact: "1.0.0"),
41+
.package(name: "swift-protobuf", url: "https://github.com/apple/swift-protobuf.git", exact: "1.20.2"),
42+
.package(name: "swift-log", url: "https://github.com/apple/swift-log.git", exact: "1.4.4"),
43+
.package(name: "swift-metrics", url: "https://github.com/apple/swift-metrics.git", exact: "2.1.1"),
44+
.package(name: "Reachability.swift", url: "https://github.com/ashleymills/Reachability.swift", exact: "5.1.0")
4545
],
4646
targets: [
4747
.target(name: "OpenTelemetryApi",

Sources/Exporters/OpenTelemetryProtocolGrpc/logs/OtlpLogExporter.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class OtlpLogExporter : LogRecordExporter {
1616
let channel : GRPCChannel
1717
var logClient : Opentelemetry_Proto_Collector_Logs_V1_LogsServiceNIOClient
1818
let config : OtlpConfiguration
19-
var callOptions : CallOptions? = nil
19+
var callOptions : CallOptions
2020

2121
public init(channel: GRPCChannel,
2222
config: OtlpConfiguration = OtlpConfiguration(),
@@ -46,6 +46,12 @@ public class OtlpLogExporter : LogRecordExporter {
4646
let logRequest = Opentelemetry_Proto_Collector_Logs_V1_ExportLogsServiceRequest.with { request in
4747
request.resourceLogs = LogRecordAdapter.toProtoResourceRecordLog(logRecordList: logRecords)
4848
}
49+
50+
if config.timeout > 0 {
51+
callOptions.timeLimit = TimeLimit.timeout(TimeAmount.nanoseconds(Int64(config.timeout.toNanoseconds)))
52+
}
53+
54+
4955
let export = logClient.export(logRequest, callOptions: callOptions)
5056
do {
5157
_ = try export.response.wait()

Sources/Exporters/OpenTelemetryProtocolGrpc/trace/OtlpTraceExporter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class OtlpTraceExporter: SpanExporter {
1616
let channel: GRPCChannel
1717
var traceClient: Opentelemetry_Proto_Collector_Trace_V1_TraceServiceNIOClient
1818
let config : OtlpConfiguration
19-
var callOptions : CallOptions? = nil
19+
var callOptions : CallOptions
2020

2121
public init(channel: GRPCChannel, config: OtlpConfiguration = OtlpConfiguration(), logger: Logging.Logger = Logging.Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }), envVarHeaders: [(String,String)]? = EnvVarHeaders.attributes) {
2222
self.channel = channel
@@ -44,7 +44,7 @@ public class OtlpTraceExporter: SpanExporter {
4444
}
4545

4646
if config.timeout > 0 {
47-
traceClient.defaultCallOptions.timeLimit = TimeLimit.timeout(TimeAmount.nanoseconds(Int64(config.timeout.toNanoseconds)))
47+
callOptions.timeLimit = TimeLimit.timeout(TimeAmount.nanoseconds(Int64(config.timeout.toNanoseconds)))
4848
}
4949

5050
let export = traceClient.export(exportRequest, callOptions: callOptions)

Sources/OpenTelemetrySdk/Trace/SpanProcessors/BatchSpanProcessor.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ private class BatchWorker: Thread {
134134
self?.exportAction(spanList: spanList)
135135
}
136136
let timeoutTimer = DispatchSource.makeTimerSource(queue: DispatchQueue.global())
137-
timeoutTimer.setEventHandler { exportOperation.cancel() }
137+
timeoutTimer.setEventHandler {
138+
exportOperation.cancel()
139+
140+
}
138141
let maxTimeOut = min(explicitTimeout ?? TimeInterval.greatestFiniteMagnitude, exportTimeout)
139142
timeoutTimer.schedule(deadline: .now() + .milliseconds(Int(maxTimeOut.toMilliseconds)), leeway: .milliseconds(1))
140143
timeoutTimer.activate()

0 commit comments

Comments
 (0)