Skip to content

Commit

Permalink
Merge pull request #472 from hunguyenaxon/hunguyen-467-469-allow-gaug…
Browse files Browse the repository at this point in the history
…e-instrument-close

Allow async instrument to close via observable
  • Loading branch information
bryce-b authored Oct 10, 2023
2 parents e2c7e6b + 9e1087d commit fc77806
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Sources/OpenTelemetryApi/Metrics/Stable/DefaultStableMeter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ public class DefaultStableMeter : StableMeter {
}
}

private struct NoopObservableLongGauge : ObservableLongGauge {}
private struct NoopObservableLongGauge : ObservableLongGauge {
func close() {}
}

private struct NoopObservableDoubleGauge : ObservableDoubleGauge {}
private struct NoopObservableDoubleGauge : ObservableDoubleGauge {
func close() {}
}

private class NoopDoubleUpDownCounterBuilder : DoubleUpDownCounterBuilder {
func build() -> DoubleUpDownCounter {
Expand All @@ -80,7 +84,9 @@ public class DefaultStableMeter : StableMeter {
}
}

private struct NoopObservableDoubleUpDownCounter : ObservableDoubleUpDownCounter {}
private struct NoopObservableDoubleUpDownCounter : ObservableDoubleUpDownCounter {
func close() {}
}

private struct NoopDoubleUpDownCounter : DoubleUpDownCounter {
mutating func add(value: Double) {}
Expand All @@ -103,7 +109,9 @@ public class DefaultStableMeter : StableMeter {
mutating func record(value: Int, attributes: [String : AttributeValue]) {}
}

private class NoopObservableLongUpDownCounter : ObservableLongUpDownCounter {}
private class NoopObservableLongUpDownCounter : ObservableLongUpDownCounter {
func close() {}
}

private class NoopDoubleHistogram : DoubleHistogram {
func record(value: Double) {}
Expand Down Expand Up @@ -139,8 +147,13 @@ public class DefaultStableMeter : StableMeter {
}
}

private class NoopObservableLongCounter : ObservableLongCounter {}
private class NoopObservableDoubleCounter: ObservableDoubleCounter {}
private class NoopObservableLongCounter : ObservableLongCounter {
func close() {}
}

private class NoopObservableDoubleCounter: ObservableDoubleCounter {
func close() {}
}

private class StableNoopDoubleCounterBuilder : DoubleCounterBuilder {
func build() -> DoubleCounter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
import Foundation

public protocol ObservableDoubleCounter {
func close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
import Foundation

public protocol ObservableDoubleGauge {
func close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
import Foundation

public protocol ObservableDoubleUpDownCounter {
func close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
import Foundation

public protocol ObservableLongCounter {
func close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
import Foundation

public protocol ObservableLongGauge {
func close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
import Foundation

public protocol ObservableLongUpDownCounter {
func close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public struct ObservableInstrumentSdk : ObservableDoubleCounter, ObservableLongC
}

// todo: Java implementation uses closeables to remove this from the meterSharedState.callback Registation. investigate alternative?
public func close() {
meterSharedState.removeCallback(callback: callbackRegistration)
}
}

0 comments on commit fc77806

Please sign in to comment.