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

nil pointer field cause panic #6235

Closed
m1heng opened this issue Oct 12, 2024 · 0 comments · Fixed by #6237
Closed

nil pointer field cause panic #6235

m1heng opened this issue Oct 12, 2024 · 0 comments · Fixed by #6237
Labels
bug Something isn't working
Milestone

Comments

@m1heng
Copy link
Contributor

m1heng commented Oct 12, 2024

Description

After add otellogrus hook, when logging with a field which contains a nil pointer would cause internal panic

Environment

  • OS: any
  • Architecture: any
  • Go Version: 1.23.0
  • go.opentelemetry.io/contrib/bridges/otellogrus version: 0.5.0

Steps To Reproduce

package main

import (
	"github.com/sirupsen/logrus"
	"go.opentelemetry.io/contrib/bridges/otellogrus"
)

type ATopicHandler struct {
	some string
}

func main() {
	var a *ATopicHandler
	logger := logrus.New()
	hook := otellogrus.NewHook("test")
	logger.AddHook(hook)
	logger.WithField("a", a).Error("error")
}
panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 1 [running]:
reflect.valueInterface({0x0?, 0x0?, 0x0?}, 0x0?)
        /Users/m1heng/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-arm64/src/reflect/value.go:1486 +0xfc
reflect.Value.Interface(...)
        /Users/m1heng/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-arm64/src/reflect/value.go:1481
go.opentelemetry.io/contrib/bridges/otellogrus.convertValue({0x10446e300, 0x0})
        /Users/m1heng/go/pkg/mod/go.opentelemetry.io/contrib/bridges/otellogrus@v0.5.0/hook.go:233 +0x3e4
go.opentelemetry.io/contrib/bridges/otellogrus.convertFields(0x1400011ca80)
        /Users/m1heng/go/pkg/mod/go.opentelemetry.io/contrib/bridges/otellogrus@v0.5.0/hook.go:180 +0xec
go.opentelemetry.io/contrib/bridges/otellogrus.(*Hook).convertEntry(_, _)
        /Users/m1heng/go/pkg/mod/go.opentelemetry.io/contrib/bridges/otellogrus@v0.5.0/hook.go:170 +0x9c
go.opentelemetry.io/contrib/bridges/otellogrus.(*Hook).Fire(0x1400011c9c0, 0x1400010ad08?)
        /Users/m1heng/go/pkg/mod/go.opentelemetry.io/contrib/bridges/otellogrus@v0.5.0/hook.go:159 +0x38
github.com/sirupsen/logrus.LevelHooks.Fire(0x1400010ad48?, 0x10ad08?, 0x1400015c0e0)
        /Users/m1heng/go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/hooks.go:28 +0x78
github.com/sirupsen/logrus.(*Entry).fireHooks(0x1400015c0e0)
        /Users/m1heng/go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:280 +0x20c
github.com/sirupsen/logrus.(*Entry).log(0x1400015c070, 0x2, {0x140001020fa, 0x5})
        /Users/m1heng/go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:242 +0x3b0
github.com/sirupsen/logrus.(*Entry).Log(0x1400015c070, 0x2, {0x1400010af28?, 0x10446e300?, 0x0?})
        /Users/m1heng/go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:304 +0x60
github.com/sirupsen/logrus.(*Entry).Error(...)
        /Users/m1heng/go/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:333
main.main()
        /Users/m1heng/xxxxx/main.go:19 +0x134
exit status 2

Expected behavior

log normally

@m1heng m1heng added the bug Something isn't working label Oct 12, 2024
pellared added a commit that referenced this issue Oct 15, 2024
…d/logutil (#6237)

Fixes #6235

Align the `convertValue` function in the `otellogrus`,
`otelzap` packages with the `otellogr`.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
@pellared pellared added this to the v1.32.0 milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants