Skip to content

Commit

Permalink
fix: return error if target binary is not set (#339)
Browse files Browse the repository at this point in the history
* 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(...)

* fix error commen typo

Co-authored-by: Przemyslaw Delewski <102958445+pdelewski@users.noreply.github.com>

---------

Co-authored-by: Przemyslaw Delewski <102958445+pdelewski@users.noreply.github.com>
  • Loading branch information
rogercoll and pdelewski authored Sep 21, 2023
1 parent a4ce6b9 commit a070680
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package auto

import (
"context"
"fmt"
"os"

"go.opentelemetry.io/auto/internal/pkg/instrumentors"
Expand All @@ -36,6 +37,12 @@ type Instrumentation struct {
manager *instrumentors.Manager
}

var (
// 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)
)

// NewInstrumentation returns a new [Instrumentation] configured with the
// provided opts.
func NewInstrumentation(opts ...InstrumentationOption) (*Instrumentation, error) {
Expand Down Expand Up @@ -119,6 +126,9 @@ func (c instConfig) applyEnv() instConfig {
}

func (c instConfig) validate() error {
if c.target == nil {
return errUndefinedTarget
}
return c.target.Validate()
}

Expand Down

0 comments on commit a070680

Please sign in to comment.