Skip to content

Commit

Permalink
otelzap: Implement encoder to map zap field to Otel attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
khushijain21 committed May 13, 2024
1 parent 985666e commit d6aab43
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions bridges/otelzap/encoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otelzap // import "go.opentelemetry.io/contrib/bridges/otelzap"

import (
"time"

"go.uber.org/zap/zapcore"

"go.opentelemetry.io/otel/log"
)

var _ zapcore.ObjectEncoder = (*objectEncoder)(nil)

// Object Encoder implements zapcore.ObjectEncoder.
// It encodes given fields to OTel attribute.
type objectEncoder struct {
kv []log.KeyValue
}

// NewObjectEncoder returns new ObjectEncoder.
func newObjectEncoder(len int) *objectEncoder {
keyval := make([]log.KeyValue, 0, len)

Check warning on line 24 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L23-L24

Added lines #L23 - L24 were not covered by tests

return &objectEncoder{
kv: keyval,

Check warning on line 27 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L26-L27

Added lines #L26 - L27 were not covered by tests
}
}

// TODO
// Converts Array to log.Slice using ArrayEncoder.
func (m *objectEncoder) AddArray(key string, v zapcore.ArrayMarshaler) error {
return nil

Check warning on line 34 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L33-L34

Added lines #L33 - L34 were not covered by tests
}

// TODO
// Converts Object to log.Map.
func (m *objectEncoder) AddObject(k string, v zapcore.ObjectMarshaler) error {
return nil

Check warning on line 40 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}

// TODO
// Converts Binary to log.Bytes.
func (m *objectEncoder) AddBinary(k string, v []byte) {

Check warning on line 45 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L45

Added line #L45 was not covered by tests
}

// TODO
// Converts ByteString to log.String.
func (m *objectEncoder) AddByteString(k string, v []byte) {

Check warning on line 50 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L50

Added line #L50 was not covered by tests
}

// TODO
// Converts Bool to log.Bool.
func (m *objectEncoder) AddBool(k string, v bool) {

Check warning on line 55 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L55

Added line #L55 was not covered by tests
}

// TODO
// Converts Duration to log.Int.
func (m *objectEncoder) AddDuration(k string, v time.Duration) {

Check warning on line 60 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L60

Added line #L60 was not covered by tests
}

// TODO
// Converts Complex128 to log.String.
func (m *objectEncoder) AddComplex128(k string, v complex128) {

Check warning on line 65 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L65

Added line #L65 was not covered by tests
}

// TODO
// Converts Float64 to log.Float64.
func (m *objectEncoder) AddFloat64(k string, v float64) {

Check warning on line 70 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L70

Added line #L70 was not covered by tests
}

// TODO
// Converts Float32 to log.Float64.
func (m *objectEncoder) AddFloat32(k string, v float32) {

Check warning on line 75 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L75

Added line #L75 was not covered by tests
}

// TODO
// Converts Int64 to logInt64.
func (m *objectEncoder) AddInt64(k string, v int64) {

Check warning on line 80 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L80

Added line #L80 was not covered by tests
}

// TODO
// Converts Int to logInt.
func (m *objectEncoder) AddInt(k string, v int) {

Check warning on line 85 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L85

Added line #L85 was not covered by tests
}

// TODO
// Converts String to logString.
func (m *objectEncoder) AddString(k string, v string) {

Check warning on line 90 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L90

Added line #L90 was not covered by tests
}

// TODO
// Converts Uint64 to logInt64/logString.
func (m *objectEncoder) AddUint64(k string, v uint64) {

Check warning on line 95 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L95

Added line #L95 was not covered by tests
}

// TODO
// Converts all non-primitive types to JSON string.
func (m *objectEncoder) AddReflected(k string, v interface{}) error {
return nil

Check warning on line 101 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L100-L101

Added lines #L100 - L101 were not covered by tests
}

// TODO
// OpenNamespace opens an isolated namespace where all subsequent fields will
// be added.
func (m *objectEncoder) OpenNamespace(k string) {

Check warning on line 107 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L107

Added line #L107 was not covered by tests
}

// TODO.
func (m *objectEncoder) AddComplex64(k string, v complex64) {}
func (m *objectEncoder) AddInt32(k string, v int32) {}
func (m *objectEncoder) AddInt16(k string, v int16) {}
func (m *objectEncoder) AddInt8(k string, v int8) {}
func (m *objectEncoder) AddTime(k string, v time.Time) {}
func (m *objectEncoder) AddUint(k string, v uint) {}
func (m *objectEncoder) AddUint32(k string, v uint32) {}
func (m *objectEncoder) AddUint16(k string, v uint16) {}
func (m *objectEncoder) AddUint8(k string, v uint8) {}
func (m *objectEncoder) AddUintptr(k string, v uintptr) {}

Check warning on line 120 in bridges/otelzap/encoder.go

View check run for this annotation

Codecov / codecov/patch

bridges/otelzap/encoder.go#L111-L120

Added lines #L111 - L120 were not covered by tests

0 comments on commit d6aab43

Please sign in to comment.