Skip to content

Commit

Permalink
to not use extra attribute variable
Browse files Browse the repository at this point in the history
  • Loading branch information
khushijain21 committed May 24, 2024
1 parent b7406f0 commit caa59bc
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions bridges/otelzap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ func (o *Core) Enabled(level zapcore.Level) bool {
func (o *Core) With(fields []zapcore.Field) zapcore.Core {
clone := o.clone()
if len(fields) > 0 {
attrbuf := convertField(fields)
clone.attr = append(clone.attr, attrbuf...)
clone.attr = append(clone.attr, convertField(fields)...)
}
return clone
}
Expand Down Expand Up @@ -156,13 +155,9 @@ func (o *Core) Write(ent zapcore.Entry, fields []zapcore.Field) error {
// TODO: Handle zap.Array.
// TODO: Handle ent.LoggerName.

r.AddAttributes(o.attr...)
if len(fields) > 0 {
attrbuf := convertField(fields)
attrbuf = slices.Grow(attrbuf, len(o.attr))
attrbuf = append(attrbuf, o.attr...)
r.AddAttributes(attrbuf...)
} else {
r.AddAttributes(o.attr...)
r.AddAttributes(convertField(fields)...)
}

o.logger.Emit(context.Background(), r)
Expand Down

0 comments on commit caa59bc

Please sign in to comment.