Skip to content

Commit 4a82e4c

Browse files
author
Ignacio Bonafonte
committed
Remove public availability of MultiSpanProcessor
All configuration for SpanProcessors is now available from TracerProviderSDK
1 parent fb3aec3 commit 4a82e4c

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

Sources/OpenTelemetrySdk/Trace/MultiSpanProcessor.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import OpenTelemetryApi
1818

1919
/// Implementation of the SpanProcessor that simply forwards all received events to a list of
2020
/// SpanProcessors.
21-
public struct MultiSpanProcessor: SpanProcessor {
21+
struct MultiSpanProcessor: SpanProcessor {
2222
var spanProcessorsStart = [SpanProcessor]()
2323
var spanProcessorsEnd = [SpanProcessor]()
2424
var spanProcessorsAll = [SpanProcessor]()
2525

26-
public init(spanProcessors: [SpanProcessor]) {
26+
init(spanProcessors: [SpanProcessor]) {
2727
spanProcessorsAll = spanProcessors
2828
spanProcessorsAll.forEach {
2929
if $0.isStartRequired {
@@ -35,33 +35,33 @@ public struct MultiSpanProcessor: SpanProcessor {
3535
}
3636
}
3737

38-
public var isStartRequired: Bool {
38+
var isStartRequired: Bool {
3939
return spanProcessorsStart.count > 0
4040
}
4141

42-
public var isEndRequired: Bool {
42+
var isEndRequired: Bool {
4343
return spanProcessorsEnd.count > 0
4444
}
4545

46-
public func onStart(parentContext: SpanContext?, span: ReadableSpan) {
46+
func onStart(parentContext: SpanContext?, span: ReadableSpan) {
4747
spanProcessorsStart.forEach {
4848
$0.onStart(parentContext: parentContext, span: span)
4949
}
5050
}
5151

52-
public func onEnd(span: ReadableSpan) {
52+
func onEnd(span: ReadableSpan) {
5353
for var processor in spanProcessorsEnd {
5454
processor.onEnd(span: span)
5555
}
5656
}
5757

58-
public func shutdown() {
58+
func shutdown() {
5959
for var processor in spanProcessorsAll {
6060
processor.shutdown()
6161
}
6262
}
6363

64-
public func forceFlush() {
64+
func forceFlush() {
6565
spanProcessorsAll.forEach {
6666
$0.forceFlush()
6767
}

Sources/OpenTelemetrySdk/Trace/TracerProviderSdk.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,28 @@ public class TracerProviderSdk: TracerProvider {
115115
sharedState.setSampler(newSampler)
116116
}
117117

118-
/// Returns the active SpanProcessor.
119-
public func getActiveSpanProcessor() -> SpanProcessor {
120-
sharedState.activeSpanProcessor
118+
/// Returns the active SpanProcessors.
119+
public func getActiveSpanProcessors() -> [SpanProcessor] {
120+
if let processor = sharedState.activeSpanProcessor as? MultiSpanProcessor {
121+
return processor.spanProcessorsAll
122+
} else {
123+
return [sharedState.activeSpanProcessor]
124+
}
121125
}
122126

123-
/// Adds a new SpanProcessor to this Tracer.
127+
/// Adds a new SpanProcessor to this TracerProvider.
124128
/// Any registered processor cause overhead, consider to use an async/batch processor especially
125129
/// for span exporting, and export to multiple backends using the MultiSpanExporter
126130
/// - Parameter spanProcessor: the new SpanProcessor to be added.
127131
public func addSpanProcessor(_ spanProcessor: SpanProcessor) {
128132
sharedState.addSpanProcessor(spanProcessor)
129133
}
130134

135+
/// Removes all SpanProcessors from this provider
136+
public func resetSpanProcessors() {
137+
sharedState.activeSpanProcessor = NoopSpanProcessor()
138+
}
139+
131140
/// Attempts to stop all the activity for this Tracer. Calls SpanProcessor.shutdown()
132141
/// for all registered SpanProcessors.
133142
/// This operation may block until all the Spans are processed. Must be called before turning

Tests/OpenTelemetrySdkTests/Trace/MultiSpanProcessorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// limitations under the License.
1414
//
1515

16-
import OpenTelemetrySdk
1716
import OpenTelemetryApi
17+
@testable import OpenTelemetrySdk
1818
import XCTest
1919

2020
class MultiSpanProcessorTest: XCTestCase {

0 commit comments

Comments
 (0)