You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following runnable code with conditional view is not working and it prints observable instrument not registered for callback message.
package main
import (
"encoding/json"
"log"
"math/rand"
"os"
"time"
"go.opentelemetry.io/contrib/instrumentation/runtime"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"go.opentelemetry.io/otel/sdk/metric"
metricsdk "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel"
)
func main() {
// Print with a JSON encoder that indents with two spaces.
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
exporter, err := stdoutmetric.New(
stdoutmetric.WithEncoder(enc),
stdoutmetric.WithoutTimestamps(),
)
if err != nil {
panic(err)
}
reader := metricsdk.NewPeriodicReader(exporter,
metricsdk.WithInterval(5*time.Second))
var drop metric.View = func(i metric.Instrument) (metric.Stream, bool) {
if i.Name != "process.runtime.go.mem.heap_alloc" {
return metricsdk.Stream{Aggregation: metricsdk.AggregationDrop{}}, true
}
return metricsdk.Stream{}, false
}
meterProvider := metricsdk.NewMeterProvider(
metricsdk.WithReader(reader),
metricsdk.WithView(drop),
)
otel.SetMeterProvider(meterProvider)
log.Print("Starting runtime instrumentation:")
err = runtime.Start(runtime.WithMinimumReadMemStatsInterval(time.Second))
if err != nil {
panic(err)
}
time.Sleep(99 * time.Minute)
}
If I remove the condition from the view and drop the aggregation, it works.
var drop metric.View = func(i metric.Instrument) (metric.Stream, bool) {
return metricsdk.Stream{Aggregation: metricsdk.AggregationDrop{}}, true
}
I opened the same ticket on opentelemetry-go (open-telemetry/opentelemetry-go#4666) some days ago but now I wonder if this is a problem specific to the instrumentation/runtime package. Same way of dropping metrics with a custom View works for other scope like: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
Collector version
v0.45.0
Environment information
No response
OpenTelemetry Collector configuration
No response
Log output
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
Component(s)
No response
What happened?
Following runnable code with conditional view is not working and it prints observable instrument not registered for callback message.
If I remove the condition from the view and drop the aggregation, it works.
I opened the same ticket on opentelemetry-go (open-telemetry/opentelemetry-go#4666) some days ago but now I wonder if this is a problem specific to the instrumentation/runtime package. Same way of dropping metrics with a custom View works for other scope like:
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
Collector version
v0.45.0
Environment information
No response
OpenTelemetry Collector configuration
No response
Log output
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: