Skip to content
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

instrumentation/runtime: observable instrument not registered for callback #28618

Closed
utezduyar opened this issue Oct 25, 2023 · 3 comments
Closed
Labels
bug Something isn't working needs triage New item requiring triage

Comments

@utezduyar
Copy link
Contributor

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.

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

@utezduyar utezduyar added bug Something isn't working needs triage New item requiring triage labels Oct 25, 2023
@mx-psi
Copy link
Member

mx-psi commented Oct 25, 2023

Sounds like you were meaning to post this on https://github.com/open-telemetry/opentelemetry-go-contrib

@Aneurysm9 maybe you have permissions to move this issue around to the right repository?

@utezduyar
Copy link
Contributor Author

Ah! Yes you're right. I don't have permission. Hope someone can help.

@utezduyar
Copy link
Contributor Author

Wrong repository. Created a new one open-telemetry/opentelemetry-go-contrib#4487

@mx-psi mx-psi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New item requiring triage
Projects
None yet
Development

No branches or pull requests

2 participants