Tracer Version(s)
1.73.1
Go Version(s)
go version go1.24.3 darwin/arm64
Bug Report
Some users may mistakenly call the Finish method of a span with nil (span.Finish(nil)) when they don't want to use any option, not realizing that Finish is a variadic function that should instead be called with no arguments in this case (span.Finish()).
Right now, Finish panics when called as Finish(nil) as it tries to dereference nil as if it was an option.
This may surprise users a bit. In general, Go packages should avoid panicking.
It may be better if Finish would check for nil options, and when detecting one, would log an error and ignore the nil option.
I am happy to write the PR.
Reproduction Code
package main
import (
"fmt"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
func main() {
tracer.Start(tracer.WithServiceName("my-service"))
defer tracer.Stop()
span := tracer.StartSpan("my-span")
span.Finish(nil)
fmt.Println("Did not panic!")
}
Error Logs
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x104c24dc4]
goroutine 1 [running]:
gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer.(*span).Finish(0x14000aa6000, {0x14000280108, 0x1, 0x140000021c0?})
/Users/cedric.vanrompay/go/pkg/mod/gopkg.in/!data!dog/[email protected]/ddtrace/tracer/span.go:552 +0x284
main.main()
/tmp/dd-trace-go-panic/main.go:14 +0xc0
Go Env Output
AR='ar' CC='cc' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_ENABLED='1' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' CXX='c++' GCCGO='gccgo' GO111MODULE='auto' GOARCH='arm64' GOARM64='v8.0' GOAUTH='netrc' GOBIN='' GOCACHE='/Users/cedric.vanrompay/dd/.go-build' GOCACHEPROG='' GODEBUG='' GOENV='/Users/cedric.vanrompay/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFIPS140='off' GOFLAGS='' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/mr/gw__5v_16b5g3kl00czl2d800000gq/T/go-build3333340776=/tmp/go-build -gno-record-gcc-switches -fno-common' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMOD='/tmp/dd-trace-go-panic/go.mod' GOMODCACHE='/Users/cedric.vanrompay/go/pkg/mod' GONOPROXY='github.com/DataDog' GONOSUMDB='github.com/DataDog' GOOS='darwin' GOPATH='/Users/cedric.vanrompay/go' GOPRIVATE='github.com/DataDog' GOPROXY='https://proxy.golang.org,direct' GOROOT='/opt/homebrew/Cellar/go/1.24.3/libexec' GOSUMDB='sum.golang.org' GOTELEMETRY='local' GOTELEMETRYDIR='/Users/cedric.vanrompay/Library/Application Support/go/telemetry' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.3/libexec/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.24.3' GOWORK='' PKG_CONFIG='pkg-config'
Tracer Version(s)
1.73.1
Go Version(s)
go version go1.24.3 darwin/arm64
Bug Report
Some users may mistakenly call the
Finishmethod of a span withnil(span.Finish(nil)) when they don't want to use any option, not realizing thatFinishis a variadic function that should instead be called with no arguments in this case (span.Finish()).Right now,
Finishpanics when called asFinish(nil)as it tries to dereferencenilas if it was an option.This may surprise users a bit. In general, Go packages should avoid panicking.
It may be better if
Finishwould check forniloptions, and when detecting one, would log an error and ignore the nil option.I am happy to write the PR.
Reproduction Code
Error Logs
Go Env Output
AR='ar' CC='cc' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_ENABLED='1' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' CXX='c++' GCCGO='gccgo' GO111MODULE='auto' GOARCH='arm64' GOARM64='v8.0' GOAUTH='netrc' GOBIN='' GOCACHE='/Users/cedric.vanrompay/dd/.go-build' GOCACHEPROG='' GODEBUG='' GOENV='/Users/cedric.vanrompay/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFIPS140='off' GOFLAGS='' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/mr/gw__5v_16b5g3kl00czl2d800000gq/T/go-build3333340776=/tmp/go-build -gno-record-gcc-switches -fno-common' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMOD='/tmp/dd-trace-go-panic/go.mod' GOMODCACHE='/Users/cedric.vanrompay/go/pkg/mod' GONOPROXY='github.com/DataDog' GONOSUMDB='github.com/DataDog' GOOS='darwin' GOPATH='/Users/cedric.vanrompay/go' GOPRIVATE='github.com/DataDog' GOPROXY='https://proxy.golang.org,direct' GOROOT='/opt/homebrew/Cellar/go/1.24.3/libexec' GOSUMDB='sum.golang.org' GOTELEMETRY='local' GOTELEMETRYDIR='/Users/cedric.vanrompay/Library/Application Support/go/telemetry' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.3/libexec/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.24.3' GOWORK='' PKG_CONFIG='pkg-config'