Skip to content

Commit d136c93

Browse files
author
Ignacio Bonafonte
committed
From review:
* Document new parameter * In BatchSpanProcessor use the lower of the timeout values
1 parent 90f3510 commit d136c93

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Sources/OpenTelemetrySdk/Trace/SpanProcessor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public protocol SpanProcessor {
1818
/// Called when a Span is started, if the Span.isRecording is true.
1919
/// This method is called synchronously on the execution thread, should not throw or block the
2020
/// execution thread.
21+
/// - Parameter parentContext: the context of the span parent, if exists
2122
/// - Parameter span: the ReadableSpan that just started
2223
func onStart(parentContext: SpanContext?, span: ReadableSpan)
2324

@@ -33,6 +34,7 @@ public protocol SpanProcessor {
3334

3435
/// Processes all span events that have not yet been processed.
3536
/// This method is executed synchronously on the calling thread
37+
/// - Parameter timeout: Maximum time the flush complete or abort. If nil, it will wait indefinitely
3638
func forceFlush(timeout: TimeInterval?)
3739
}
3840

Sources/OpenTelemetrySdk/Trace/SpanProcessors/BatchSpanProcessor.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ private class BatchWorker: Thread {
135135
}
136136
let timeoutTimer = DispatchSource.makeTimerSource(queue: DispatchQueue.global())
137137
timeoutTimer.setEventHandler { exportOperation.cancel() }
138-
timeoutTimer.schedule(deadline: .now() + .milliseconds(Int(explicitTimeout?.toMilliseconds ?? exportTimeout.toMilliseconds)), leeway: .milliseconds(1))
138+
let maxTimeOut = min(explicitTimeout ?? TimeInterval.greatestFiniteMagnitude, exportTimeout)
139+
timeoutTimer.schedule(deadline: .now() + .milliseconds(Int(maxTimeOut.toMilliseconds)), leeway: .milliseconds(1))
139140
timeoutTimer.activate()
140141
queue.addOperation(exportOperation)
141142
queue.waitUntilAllOperationsAreFinished()

0 commit comments

Comments
 (0)