Skip to content

Commit 044f0fd

Browse files
author
Ignacio Bonafonte
authored
Review visibility of classes and methods, some of them could not be used properly outside of the library (#81)
Convert some Metrics classes to structs, since are not meant to be inherited Modify tests import so only those files needing non public access import libraries as `@testable` Code styling done to the modified files
1 parent acc2aa9 commit 044f0fd

File tree

57 files changed

+151
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+151
-171
lines changed

Sources/OpenTelemetryApi/Context/Propagation/DefaultContextPropagators.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import Foundation
2121
public struct DefaultContextPropagators: ContextPropagators {
2222
public var httpTextFormat: HTTPTextFormattable
2323

24-
init() {
24+
public init() {
2525
httpTextFormat = NoopHttpTextFormat()
2626
}
2727

28-
init(textPropagators: [HTTPTextFormattable]) {
28+
public init(textPropagators: [HTTPTextFormattable]) {
2929
httpTextFormat = MultiHttpTextFormat(textPropagators: textPropagators)
3030
}
3131

@@ -76,8 +76,7 @@ public struct DefaultContextPropagators: ContextPropagators {
7676
struct NoopHttpTextFormat: HTTPTextFormattable {
7777
public var fields = Set<String>()
7878

79-
public func inject<S>(spanContext: SpanContext, carrier: inout [String: String], setter: S) where S: Setter {
80-
}
79+
public func inject<S>(spanContext: SpanContext, carrier: inout [String: String], setter: S) where S: Setter {}
8180

8281
public func extract<G>(spanContext: SpanContext?, carrier: [String: String], getter: G) -> SpanContext? where G: Getter {
8382
return spanContext

Sources/OpenTelemetryApi/CorrelationContext/DefaultCorrelationContextManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Foundation
1919
public class DefaultCorrelationContextManager: CorrelationContextManager {
2020
/// Returns a CorrelationContextManager singleton that is the default implementation for
2121
/// CorrelationContextManager.
22-
static var instance = DefaultCorrelationContextManager()
22+
public static var instance = DefaultCorrelationContextManager()
2323

2424
private init() {}
2525

Sources/OpenTelemetryApi/CorrelationContext/EntryMetadata.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum EntryTtl: Equatable {
3838
}
3939

4040
public struct EntryMetadata: Equatable {
41-
var entryTtl: EntryTtl
41+
public var entryTtl: EntryTtl
4242

4343
public init(entryTtl: EntryTtl) {
4444
self.entryTtl = entryTtl

Sources/OpenTelemetryApi/Metrics/CounterMetric.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ public struct AnyCounterMetric<T>: CounterMetric {
7676
}
7777
}
7878

79-
struct NoopCounterMetric<T>: CounterMetric {
80-
func add(value: T, labelset: LabelSet) {
81-
}
79+
public struct NoopCounterMetric<T>: CounterMetric {
80+
public init() {}
8281

83-
func add(value: T, labels: [String: String]) {
84-
}
82+
public func add(value: T, labelset: LabelSet) {}
83+
84+
public func add(value: T, labels: [String: String]) {}
8585

86-
func bind(labelset: LabelSet) -> BoundCounterMetric<T> {
86+
public func bind(labelset: LabelSet) -> BoundCounterMetric<T> {
8787
return BoundCounterMetric<T>()
8888
}
8989

90-
func bind(labels: [String: String]) -> BoundCounterMetric<T> {
90+
public func bind(labels: [String: String]) -> BoundCounterMetric<T> {
9191
return BoundCounterMetric<T>()
9292
}
9393
}

Sources/OpenTelemetryApi/Metrics/DefaultMeterProvider.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
import Foundation
1717

18-
class DefaultMeterProvider: MeterProvider {
19-
static var instance: MeterProvider = DefaultMeterProvider()
18+
public class DefaultMeterProvider: MeterProvider {
19+
public static var instance: MeterProvider = DefaultMeterProvider()
2020

2121
static var proxyMeter = ProxyMeter()
2222
static var initialized = false
2323

24-
public init() {}
24+
init() {}
2525

26-
static func setDefault(meterFactory: MeterProvider) {
26+
public static func setDefault(meterFactory: MeterProvider) {
2727
guard !initialized else {
2828
return
2929
}
@@ -32,7 +32,7 @@ class DefaultMeterProvider: MeterProvider {
3232
initialized = true
3333
}
3434

35-
func get(instrumentationName: String, instrumentationVersion: String? = nil) -> Meter {
35+
public func get(instrumentationName: String, instrumentationVersion: String? = nil) -> Meter {
3636
return DefaultMeterProvider.initialized ? DefaultMeterProvider.instance.get(instrumentationName: instrumentationName, instrumentationVersion: instrumentationVersion) : DefaultMeterProvider.proxyMeter
3737
}
3838

Sources/OpenTelemetryApi/Metrics/DoubleObserverMetric.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import Foundation
1717

1818
/// Observer instrument for Double values.
19-
public protocol DoubleObserverMetric: AnyObject {
19+
public protocol DoubleObserverMetric {
2020
/// Observes a value.
2121
/// - Parameters:
2222
/// - value: value to observe.
@@ -31,10 +31,10 @@ public protocol DoubleObserverMetric: AnyObject {
3131
func observe(value: Double, labels: [String: String])
3232
}
3333

34-
class NoopDoubleObserverMetric: DoubleObserverMetric {
35-
func observe(value: Double, labelset: LabelSet) {
36-
}
34+
public struct NoopDoubleObserverMetric: DoubleObserverMetric {
35+
public init() {}
3736

38-
func observe(value: Double, labels: [String: String]) {
39-
}
37+
public func observe(value: Double, labelset: LabelSet) {}
38+
39+
public func observe(value: Double, labels: [String: String]) {}
4040
}

Sources/OpenTelemetryApi/Metrics/IntObserverMetric.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import Foundation
1717

1818
/// Observer instrument for Int values.
19-
public protocol IntObserverMetric: AnyObject {
19+
public protocol IntObserverMetric {
2020
/// Observes a value.
2121
/// - Parameters:
2222
/// - value: value to observe.
@@ -31,10 +31,10 @@ public protocol IntObserverMetric: AnyObject {
3131
func observe(value: Int, labels: [String: String])
3232
}
3333

34-
class NoopIntObserverMetric: IntObserverMetric {
35-
func observe(value: Int, labelset: LabelSet) {
36-
}
34+
public struct NoopIntObserverMetric: IntObserverMetric {
35+
public init() {}
3736

38-
func observe(value: Int, labels: [String: String]) {
39-
}
37+
public func observe(value: Int, labelset: LabelSet) {}
38+
39+
public func observe(value: Int, labels: [String: String]) {}
4040
}

Sources/OpenTelemetryApi/Metrics/MeasureMetric.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ public struct AnyMeasureMetric<T>: MeasureMetric {
6868
}
6969
}
7070

71-
struct NoopMeasureMetric<T>: MeasureMetric {
72-
func bind(labelset: LabelSet) -> BoundMeasureMetric<T> {
71+
public struct NoopMeasureMetric<T>: MeasureMetric {
72+
public init() {}
73+
74+
public func bind(labelset: LabelSet) -> BoundMeasureMetric<T> {
7375
BoundMeasureMetric<T>()
7476
}
7577

76-
func bind(labels: [String: String]) -> BoundMeasureMetric<T> {
78+
public func bind(labels: [String: String]) -> BoundMeasureMetric<T> {
7779
BoundMeasureMetric<T>()
7880
}
7981
}

Sources/OpenTelemetryApi/Metrics/Meter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import Foundation
1717

1818
/// Main interface to obtain metric instruments.
19-
public protocol Meter: AnyObject {
19+
public protocol Meter {
2020
/// Creates Int counter with given name.
2121
/// - Parameters:
2222
/// - name: The name of the counter.

Sources/OpenTelemetryApi/Metrics/ProxyMeter.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@
1616
import Foundation
1717

1818
/// Proxy Meter which act as a No-Op Meter, until real meter is provided.
19-
class ProxyMeter: Meter {
19+
public struct ProxyMeter: Meter {
2020
private var realMeter: Meter?
2121

22-
func getLabelSet(labels: [String: String]) -> LabelSet {
22+
public func getLabelSet(labels: [String: String]) -> LabelSet {
2323
return realMeter?.getLabelSet(labels: labels) ?? LabelSet.empty
2424
}
2525

26-
func createIntCounter(name: String, monotonic: Bool) -> AnyCounterMetric<Int> {
26+
public func createIntCounter(name: String, monotonic: Bool) -> AnyCounterMetric<Int> {
2727
return realMeter?.createIntCounter(name: name, monotonic: monotonic) ?? AnyCounterMetric<Int>(NoopCounterMetric<Int>())
2828
}
2929

30-
func createDoubleCounter(name: String, monotonic: Bool) -> AnyCounterMetric<Double> {
30+
public func createDoubleCounter(name: String, monotonic: Bool) -> AnyCounterMetric<Double> {
3131
return realMeter?.createDoubleCounter(name: name, monotonic: monotonic) ?? AnyCounterMetric<Double>(NoopCounterMetric<Double>())
3232
}
3333

34-
func createIntMeasure(name: String, absolute: Bool) -> AnyMeasureMetric<Int> {
34+
public func createIntMeasure(name: String, absolute: Bool) -> AnyMeasureMetric<Int> {
3535
return realMeter?.createIntMeasure(name: name, absolute: absolute) ?? AnyMeasureMetric<Int>(NoopMeasureMetric<Int>())
3636
}
3737

38-
func createDoubleMeasure(name: String, absolute: Bool) -> AnyMeasureMetric<Double> {
38+
public func createDoubleMeasure(name: String, absolute: Bool) -> AnyMeasureMetric<Double> {
3939
return realMeter?.createDoubleMeasure(name: name, absolute: absolute) ?? AnyMeasureMetric<Double>(NoopMeasureMetric<Double>())
4040
}
4141

42-
func createIntObserver(name: String, absolute: Bool, callback: @escaping (IntObserverMetric) -> Void) -> IntObserverMetric {
42+
public func createIntObserver(name: String, absolute: Bool, callback: @escaping (IntObserverMetric) -> Void) -> IntObserverMetric {
4343
return realMeter?.createIntObserver(name: name, absolute: absolute, callback: callback) ?? NoopIntObserverMetric()
4444
}
4545

46-
func createDoubleObserver(name: String, absolute: Bool, callback: @escaping (DoubleObserverMetric) -> Void) -> DoubleObserverMetric {
46+
public func createDoubleObserver(name: String, absolute: Bool, callback: @escaping (DoubleObserverMetric) -> Void) -> DoubleObserverMetric {
4747
return realMeter?.createDoubleObserver(name: name, absolute: absolute, callback: callback) ?? NoopDoubleObserverMetric()
4848
}
4949

50-
func updateMeter(realMeter: Meter) {
50+
mutating func updateMeter(realMeter: Meter) {
5151
guard self.realMeter == nil else {
5252
return
5353
}

0 commit comments

Comments
 (0)