alibaba / opentelemetry-go-auto-instrumentation

OpenTelemetry Compile-Time Instrumentation for Golang
Apache License 2.0
95 stars 14 forks source link

[Bug] Bad initialization order of hooks #48

Open y1yang0 opened 1 month ago

y1yang0 commented 1 month ago

The incorrect initialization order of hooks led to them not being called correctly.

The key issue is that even if we add import otel_rules at the beginning of main.go to initialize the hook, we cannot ensure that it initializes before other packages. This is due to the lack of such guarantees in both the language specification and the compiler implementation. We need to have our hook setup in advance. One simple workaround is to find all the files in the user's project that contain init and add import otel_rules within them. This way, otel_rules becomes a dependency for all related packages, ensuring it is executed first. However, this approach is not elegant and feels rather stupid. We are considering a more clever solution using go:linkname.