From caa59bc1e65726c2b33f93e31c2d8ed431990c06 Mon Sep 17 00:00:00 2001 From: khushijain21 Date: Fri, 24 May 2024 09:24:35 +0530 Subject: [PATCH] to not use extra attribute variable --- bridges/otelzap/core.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/bridges/otelzap/core.go b/bridges/otelzap/core.go index 28660684c3f..89f0e580ed9 100644 --- a/bridges/otelzap/core.go +++ b/bridges/otelzap/core.go @@ -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 } @@ -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)