-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to implement Prometheus Gauge Set method in open-telemetry? #3984
Comments
The specification have add an sync gauge at https://github.com/open-telemetry/opentelemetry-specification/pull/3540,is there any plan to implement it in go? |
When it becomes stable in the specification, yes. |
You can (relatively easily) work around this using asynchronous gauges: func ExampleSynchronousGauge() {
myGauge := NewFloat64Gauge()
_, err := meter.Float64ObservableGauge(
"my.metric.name",
metric.WithUnit("s"),
metric.WithInt64Callback(myGauge.Callback),
)
if err != nil {
panic(err)
}
// use your synchronous gauge!
myGauge.Set(3.14, attribute.NewSet(attribute.String("one", "1")))
myGauge.Set(3.14159, attribute.NewSet(attribute.String("one", "bar")))
// Later, if I want to stop exporting that attribute set:
myGauge.Delete(attribute.NewSet(attribute.String("one", "1")))
}
func NewFloat64Gauge() *Float64Gauge {
return &Float64Gauge{observations: make(map[attribute.Set]float64)}
}
type Float64Gauge struct {
observations map[attribute.Set]float64
}
// Callback implements the callback function for the underlying asynchronous gauge
// it observes the current state of all previous Set() calls.
func (f *Float64Gauge) Callback(ctx context.Context, o metric.Float64Observer) error {
for attrs, val := range f.observations {
o.Observe(val, metric.WithAttributeSet(attrs))
}
return nil
}
func (f *Float64Gauge) Set(val float64, attrs attribute.Set) {
f.observations[attrs] = val
}
func (f *Float64Gauge) Delete(attrs attribute.Set) {
delete(f.observations, attrs)
} |
I don't think this should block the prometheus exporter's GA. |
Seems sync gauge already released in specs (https://github.com/open-telemetry/opentelemetry-specification/releases/tag/v1.25.0) Are there any support plans for golang? |
We likely won't support it until it is promoted to stable. |
I've worked it around by implementing gauge using the example of OpenTelemetry Will replace my workaround with the original synchronous Gauge once it's implemented. |
Problem Statement
A clear and concise description of what the problem is.
Ex. I'm always frustrated when [...]
I'm trying to migrate an project's metric implement from Prometheus to open-telemetry,it heavily use gauge.Set to measure values with different labels group. For example:
It have an gauge metric for conn pool stats, defined as:
and type's value could be one of: free、running as so on.
On other hand, another library we used only expose an
Store
method to the user, which is been called when the library want to set a metric to an concrete value (with different labels group), we implementStore
use gauge.Set method. but when we migrate to open-telemetry,we only have two choice:Store
at any time.base on this discription,how should implement gauge.Set method in open-telemetry with different label groups?
I have search for previous issue,and found #708 (comment) is and similar requests.
Proposed Solution
A clear and concise description of what you want to happen.
Alternatives
A clear and concise description of any alternative solutions or features you've considered.
Prior Art
A clear and concise list of any similar and existing solutions from other projects that provide context to possible solutions.
Additional Context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: