From 5a74349528d228920b390aa18587857abca4df98 Mon Sep 17 00:00:00 2001 From: Roger Coll Date: Thu, 21 Sep 2023 15:22:59 +0200 Subject: [PATCH 1/2] fix: return error if target binary is not set If OTEL_GO_AUTO_TARGET_EXE is not defined, a runtime panic is triggered: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x96796c] goroutine 1 [running]: go.opentelemetry.io/auto/internal/pkg/process.(*TargetArgs).Validate(...) --- CHANGELOG.md | 4 ++++ instrumentation.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7088ecb3..778c8bd47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http ## [Unreleased] +### Changed + +- Fix runtime panic if OTEL_GO_AUTO_TARGET_EXE is not set. ([#339](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/339)) + ### Deprecated - The `go.opentelemetry.io/auto/examples/rolldice` module is deprecated. diff --git a/instrumentation.go b/instrumentation.go index 299458fd2..dc7f865c7 100644 --- a/instrumentation.go +++ b/instrumentation.go @@ -16,6 +16,7 @@ package auto import ( "context" + "fmt" "os" "go.opentelemetry.io/auto/internal/pkg/instrumentors" @@ -36,6 +37,12 @@ type Instrumentation struct { manager *instrumentors.Manager } +var ( + // Error message returned when instrumentation is launched without a taget + // binary. + errUndefinedTarget = fmt.Errorf("undefined target Go binary, consider setting the %s environment variable pointing to the target binary to instrument", envTargetExeKey) +) + // NewInstrumentation returns a new [Instrumentation] configured with the // provided opts. func NewInstrumentation(opts ...InstrumentationOption) (*Instrumentation, error) { @@ -119,6 +126,9 @@ func (c instConfig) applyEnv() instConfig { } func (c instConfig) validate() error { + if c.target == nil { + return errUndefinedTarget + } return c.target.Validate() } From 9bdac038ef482b2a35a7bf7053c032662329e097 Mon Sep 17 00:00:00 2001 From: Roger Coll Date: Thu, 21 Sep 2023 15:43:31 +0200 Subject: [PATCH 2/2] fix error commen typo Co-authored-by: Przemyslaw Delewski <102958445+pdelewski@users.noreply.github.com> --- instrumentation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation.go b/instrumentation.go index dc7f865c7..4712a3be3 100644 --- a/instrumentation.go +++ b/instrumentation.go @@ -38,7 +38,7 @@ type Instrumentation struct { } var ( - // Error message returned when instrumentation is launched without a taget + // Error message returned when instrumentation is launched without a target // binary. errUndefinedTarget = fmt.Errorf("undefined target Go binary, consider setting the %s environment variable pointing to the target binary to instrument", envTargetExeKey) )