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: Add caller and stacktrace to attributes if present #6268

Merged
merged 14 commits into from
Oct 24, 2024
7 changes: 7 additions & 0 deletions bridges/otelzap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ func (o *Core) Write(ent zapcore.Entry, fields []zapcore.Field) error {
r.SetSeverityText(ent.Level.String())

r.AddAttributes(o.attr...)
if ent.Caller.Defined {
r.AddAttributes(
log.String("file", ent.Caller.File),
log.Int("line", ent.Caller.Line),
log.String("function", ent.Caller.Function),
suniastar marked this conversation as resolved.
Show resolved Hide resolved
)
}
if len(fields) > 0 {
ctx, attrbuf := convertField(fields)
if ctx != nil {
Expand Down