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

[otelzap] Issues with creating otelzap sugarred logger with options #81

Open
GinkT opened this issue Oct 14, 2022 · 0 comments
Open

[otelzap] Issues with creating otelzap sugarred logger with options #81

GinkT opened this issue Oct 14, 2022 · 0 comments

Comments

@GinkT
Copy link

GinkT commented Oct 14, 2022

Trying to create a wrapper pkg for otelzap logger

package logger

type logger struct {
	z  *zap.SugaredLogger
	oz *otelzap.SugaredLogger
}

var globalLogger *logger

func init() {
	level := getLoggerLevel(os.Getenv("LOGGER_LEVEL"))

	encoderConfig := zap.NewProductionEncoderConfig()
	encoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder

	zapLogger, err := zap.Config{
		Level:            zap.NewAtomicLevelAt(level),
		Development:      true,
		Encoding:         "console",
		EncoderConfig:    encoderConfig,
		OutputPaths:      []string{"stderr"},
		ErrorOutputPaths: []string{"stderr"},
	}.Build(zap.WithCaller(true), zap.AddStacktrace(zapcore.ErrorLevel), zap.AddCallerSkip(1))
	if err != nil {
		panic(err)
	}

	globalLogger = &logger{
		z:  zapLogger.Sugar(),
		oz: otelzap.New(zapLogger, otelzap.WithCaller(false), otelzap.WithTraceIDField(true)).Sugar(),
	}
}

func DebugwContext(ctx context.Context, msg string, keysAndValues ...interface{}) {
	globalLogger.oz.DebugwContext(ctx, msg, keysAndValues...)
}

But when i try to execute DebugwContext which uses otelzap logger i see a caller(even if im passed caller false option and don't see a traceId field)

logger.DebugwContext(ctx, "i'm traced btw", []interface{}{}...)

output:
2022-10-14T10:45:54+03:00       debug   logger/logger.go:83     i'm traced btw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant