From a9deaf7d335af38aba889a97eb8ff3b59b437fbc Mon Sep 17 00:00:00 2001 From: David Muir Sharnoff Date: Sat, 24 Sep 2022 22:57:57 -0700 Subject: [PATCH] remove xopbase.Line.Error, add ErrorReactionFunc --- basegroup.go | 36 +++---- line.go | 17 ++- line.zzzgo | 20 +++- sub.go | 144 +++++++++++++++++-------- sub.zzzgo | 93 +++++++++++----- tools/xopzzz/xopzzz.go | 7 +- xopbase/base.go | 12 +-- xopbase/base.zzzgo | 7 -- xopbase/datatype_enumer.go | 216 +++++++++++++++++++------------------ xopjson/jsonlogger.go | 23 ++-- xopjson/jsonlogger.zzzgo | 23 ++-- xopjson/jsonlogger_test.go | 6 +- xopotel/otel.go | 12 +-- xopotel/otel.zzzgo | 11 +- xopotel/otel_test.go | 4 - xoptest/testlogger.go | 3 +- xoputil/skip.go | 3 +- 17 files changed, 350 insertions(+), 287 deletions(-) diff --git a/basegroup.go b/basegroup.go index 67266041..41974137 100644 --- a/basegroup.go +++ b/basegroup.go @@ -207,24 +207,12 @@ func (p prefillings) Duration(k string, v time.Duration) { } } -func (p prefillings) Error(k string, v error) { - for _, prefilling := range p { - prefilling.Error(k, v) - } -} - func (p prefillings) Link(k string, v trace.Trace) { for _, prefilling := range p { prefilling.Link(k, v) } } -func (p prefillings) String(k string, v string) { - for _, prefilling := range p { - prefilling.String(k, v) - } -} - func (p prefillings) Time(k string, v time.Time) { for _, prefilling := range p { prefilling.Time(k, v) @@ -243,6 +231,12 @@ func (p prefillings) Int64(k string, v int64, dt xopbase.DataType) { } } +func (p prefillings) String(k string, v string, dt xopbase.DataType) { + for _, prefilling := range p { + prefilling.String(k, v, dt) + } +} + func (p prefillings) Uint64(k string, v uint64, dt xopbase.DataType) { for _, prefilling := range p { prefilling.Uint64(k, v, dt) @@ -267,24 +261,12 @@ func (l lines) Duration(k string, v time.Duration) { } } -func (l lines) Error(k string, v error) { - for _, line := range l { - line.Error(k, v) - } -} - func (l lines) Link(k string, v trace.Trace) { for _, line := range l { line.Link(k, v) } } -func (l lines) String(k string, v string) { - for _, line := range l { - line.String(k, v) - } -} - func (l lines) Time(k string, v time.Time) { for _, line := range l { line.Time(k, v) @@ -303,6 +285,12 @@ func (l lines) Int64(k string, v int64, dt xopbase.DataType) { } } +func (l lines) String(k string, v string, dt xopbase.DataType) { + for _, line := range l { + line.String(k, v, dt) + } +} + func (l lines) Uint64(k string, v uint64, dt xopbase.DataType) { for _, line := range l { line.Uint64(k, v, dt) diff --git a/line.go b/line.go index cd237ffb..f6a37352 100644 --- a/line.go +++ b/line.go @@ -70,6 +70,18 @@ func (line *Line) Enum(k *xopat.EnumAttribute, v xopat.Enum) *Line { return line } +func (line *Line) Error(k string, v error) *Line { + if line.skip { + return line + } + if line.log.settings.redactError != nil { + line.log.settings.redactError(line.line, k, v) + return line + } + line.line.String(k, v.Error(), xopbase.ErrorDataType) + return line +} + func (line *Line) Stringer(k string, v fmt.Stringer) *Line { if line.skip { return line @@ -78,7 +90,7 @@ func (line *Line) Stringer(k string, v fmt.Stringer) *Line { line.log.settings.redactString(line.line, k, v.String()) return line } - line.line.String(k, v.String()) + line.line.String(k, v.String(), xopbase.StringerDataType) return line } @@ -90,13 +102,12 @@ func (line *Line) String(k string, v string) *Line { line.log.settings.redactString(line.line, k, v) return line } - line.line.String(k, v) + line.line.String(k, v, xopbase.StringDataType) return line } func (line *Line) Bool(k string, v bool) *Line { line.line.Bool(k, v); return line } func (line *Line) Duration(k string, v time.Duration) *Line { line.line.Duration(k, v); return line } -func (line *Line) Error(k string, v error) *Line { line.line.Error(k, v); return line } func (line *Line) Link(k string, v trace.Trace) *Line { line.line.Link(k, v); return line } func (line *Line) Time(k string, v time.Time) *Line { line.line.Time(k, v); return line } diff --git a/line.zzzgo b/line.zzzgo index d19391dd..ac1cdaa4 100644 --- a/line.zzzgo +++ b/line.zzzgo @@ -63,6 +63,18 @@ func (line *Line) Enum(k *xopat.EnumAttribute, v xopat.Enum) *Line { return line } +func (line *Line) Error(k string, v error) *Line { + if line.skip { + return line + } + if line.log.settings.redactError != nil { + line.log.settings.redactError(line.line, k, v) + return line + } + line.line.String(k, v.Error(), xopbase.ErrorDataType) + return line +} + func (line *Line) Stringer(k string, v fmt.Stringer) *Line { if line.skip { return line @@ -71,7 +83,7 @@ func (line *Line) Stringer(k string, v fmt.Stringer) *Line { line.log.settings.redactString(line.line, k, v.String()) return line } - line.line.String(k, v.String()) + line.line.String(k, v.String(), xopbase.StringerDataType) return line } @@ -83,14 +95,14 @@ func (line *Line) String(k string, v string) *Line { line.log.settings.redactString(line.line, k, v) return line } - line.line.String(k, v) + line.line.String(k, v, xopbase.StringDataType) return line } -// MACRO BaseDataWithoutType SKIP:Any,String +// MACRO BaseDataWithoutType SKIP:Any func (line *Line) ZZZ(k string, v zzz) *Line { line.line.ZZZ(k, v); return line } -// MACRO BaseDataWithType +// MACRO BaseDataWithType SKIP:String func (line *Line) ZZZ(k string, v zzz) *Line { line.line.ZZZ(k, v, xopbase.ZZZDataType) return line diff --git a/sub.go b/sub.go index e03d64ab..bcd2745b 100644 --- a/sub.go +++ b/sub.go @@ -38,10 +38,10 @@ type Detaching struct { // the function call. type RedactAnyFunc func(baseLine xopbase.Line, k string, v interface{}, alreadyImmutable bool) -// RedactStringFunc is used to redact strings as they're bing logged. +// RedactStringFunc is used to redact strings as they're being logged. // It is RedactStringFunc's responsiblity to call // -// baseLine.String(k, v) +// baseLine.String(k, v, xopbase.StringDataType) // // if it wants the value to be logged. // @@ -49,6 +49,20 @@ type RedactAnyFunc func(baseLine xopbase.Line, k string, v interface{}, alreadyI // the function call. type RedactStringFunc func(baseLine xopbase.Line, k string, v string) +// RedactErrorFunc is used to redact or format errors as they're being +// logged. It is RedactErrorFunc's responsibility to call +// +// baseLine.String(k, v.Error(), xopbase.ErrorDataType) +// +// if it wants the value to be logged. Alternatively, it could log the +// error as a model: +// +// baseLine.Any(k, v) +// +// The provided xopbase.Line may not be retained beyond the duration of +// the function call. +type RedactErrorFunc func(baseLine xopbase.Line, k string, v error) + type LogSettings struct { prefillMsg string prefillData []func(xopbase.Prefilling) @@ -58,6 +72,7 @@ type LogSettings struct { synchronousFlushWhenDone bool redactAny RedactAnyFunc redactString RedactStringFunc + redactError RedactErrorFunc } // DefaultSettings are the settings that are used if no setting changes @@ -238,7 +253,7 @@ func (log *Log) sendPrefill() { f(prefilling) } if log.settings.tagLinesWithSpanSequence { - prefilling.String(xopconst.SpanSequenceCode.Key(), log.span.seed.spanSequenceCode) + prefilling.String(xopconst.SpanSequenceCode.Key(), log.span.seed.spanSequenceCode, xopbase.StringDataType) } log.prefilled = prefilling.PrefillComplete(log.settings.prefillMsg) } @@ -273,11 +288,29 @@ func (settings *LogSettings) PrefillEnum(k *xopat.EnumAttribute, v xopat.Enum) { }) } +// PrefillError is used to set a data element that is included on every log +// line. Errors will always be formatted with v.Error(). Redaction is +// not supported. +func (sub *Sub) PrefillError(k string, v error) *Sub { + sub.settings.PrefillError(k, v) + return sub +} + +// PrefillError is used to set a data element that is included on every log +// line. Errors will always be formatted with v.Error(). Redaction is +// not supported. +func (settings *LogSettings) PrefillError(k string, v error) { + settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { + line.String(k, v.Error(), xopbase.ErrorDataType) + }) +} + // PrefillAny is used to set a data element that is included on every log // line. Values provided with PrefillAny will be copied // using https://github.com/mohae/deepcopy 's Copy(). // PrefillAny is not threadsafe with respect to other calls on the same *Sub. // Should not be used after Step(), Fork(), or Log() is called. +// Redaction is not supported. func (sub *Sub) PrefillAny(k string, v interface{}) *Sub { sub.settings.PrefillAny(k, v) return sub @@ -288,12 +321,28 @@ func (sub *Sub) PrefillAny(k string, v interface{}) *Sub { // using https://github.com/mohae/deepcopy 's Copy(). // PrefillAny is not threadsafe with respect to other calls on the same *Sub. // Should not be used after Step(), Fork(), or Log() is called. +// Redaction is not supported. func (settings *LogSettings) PrefillAny(k string, v interface{}) { settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { line.Any(k, v) }) } +// PrefillFloat32 is used to set a data element that is included on every log +// line. +// PrefillFloat32 is not threadsafe with respect to other calls on the same *Sub. +// Should not be used after Step(), Fork(), or Log() is called. +func (sub *Sub) PrefillFloat32(k string, v float32) *Sub { + sub.settings.PrefillFloat32(k, v) + return sub +} + +func (settings *LogSettings) PrefillFloat32(k string, v float32) { + settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { + line.Float64(k, float64(v), xopbase.Float32DataType) + }) +} + // PrefillBool is used to set a data element that is included on every log // line. // PrefillBool is not threadsafe with respect to other calls on the same *Sub. @@ -324,21 +373,6 @@ func (settings *LogSettings) PrefillDuration(k string, v time.Duration) { }) } -// PrefillError is used to set a data element that is included on every log -// line. -// PrefillError is not threadsafe with respect to other calls on the same *Sub. -// Should not be used after Step(), Fork(), or Log() is called. -func (sub *Sub) PrefillError(k string, v error) *Sub { - sub.settings.PrefillError(k, v) - return sub -} - -func (settings *LogSettings) PrefillError(k string, v error) { - settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { - line.Error(k, v) - }) -} - // PrefillLink is used to set a data element that is included on every log // line. // PrefillLink is not threadsafe with respect to other calls on the same *Sub. @@ -354,21 +388,6 @@ func (settings *LogSettings) PrefillLink(k string, v trace.Trace) { }) } -// PrefillString is used to set a data element that is included on every log -// line. -// PrefillString is not threadsafe with respect to other calls on the same *Sub. -// Should not be used after Step(), Fork(), or Log() is called. -func (sub *Sub) PrefillString(k string, v string) *Sub { - sub.settings.PrefillString(k, v) - return sub -} - -func (settings *LogSettings) PrefillString(k string, v string) { - settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { - line.String(k, v) - }) -} - // PrefillTime is used to set a data element that is included on every log // line. // PrefillTime is not threadsafe with respect to other calls on the same *Sub. @@ -414,6 +433,21 @@ func (settings *LogSettings) PrefillInt64(k string, v int64) { }) } +// PrefillString is used to set a data element that is included on every log +// line. +// PrefillString is not threadsafe with respect to other calls on the same *Sub. +// Should not be used after Step(), Fork(), or Log() is called. +func (sub *Sub) PrefillString(k string, v string) *Sub { + sub.settings.PrefillString(k, v) + return sub +} + +func (settings *LogSettings) PrefillString(k string, v string) { + settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { + line.String(k, v, xopbase.StringDataType) + }) +} + // PrefillUint64 is used to set a data element that is included on every log // line. // PrefillUint64 is not threadsafe with respect to other calls on the same *Sub. @@ -549,17 +583,41 @@ func (settings *LogSettings) PrefillUint8(k string, v uint8) { }) } -// PrefillFloat32 is used to set a data element that is included on every log -// line. -// PrefillFloat32 is not threadsafe with respect to other calls on the same *Sub. -// Should not be used after Step(), Fork(), or Log() is called. -func (sub *Sub) PrefillFloat32(k string, v float32) *Sub { - sub.settings.PrefillFloat32(k, v) +// SetRedactAnyFunc sets a redaction function to be used +// when Line.Any() is called. +func (sub *Sub) SetRedactAnyFunc(f RedactAnyFunc) *Sub { + sub.settings.SetRedactAnyFunc(f) return sub } -func (settings *LogSettings) PrefillFloat32(k string, v float32) { - settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { - line.Float64(k, float64(v), xopbase.Float32DataType) - }) +// SetRedactErrorFunc sets a redaction function to be used +// when Line.Error() is called. +func (sub *Sub) SetRedactErrorFunc(f RedactErrorFunc) *Sub { + sub.settings.SetRedactErrorFunc(f) + return sub +} + +// SetRedactStringFunc sets a redaction function to be used +// when Line.String() is called. +func (sub *Sub) SetRedactStringFunc(f RedactStringFunc) *Sub { + sub.settings.SetRedactStringFunc(f) + return sub +} + +// SetRedactAnyFunc sets a redaction function to be used +// when Line.Any() is called. +func (settings *LogSettings) SetRedactAnyFunc(f RedactAnyFunc) { + settings.redactAny = f +} + +// SetRedactErrorFunc sets a redaction function to be used +// when Line.Error() is called. +func (settings *LogSettings) SetRedactErrorFunc(f RedactErrorFunc) { + settings.redactError = f +} + +// SetRedactStringFunc sets a redaction function to be used +// when Line.String() is called. +func (settings *LogSettings) SetRedactStringFunc(f RedactStringFunc) { + settings.redactString = f } diff --git a/sub.zzzgo b/sub.zzzgo index 46d291e2..0acd028d 100644 --- a/sub.zzzgo +++ b/sub.zzzgo @@ -34,10 +34,10 @@ type Detaching struct { // the function call. type RedactAnyFunc func(baseLine xopbase.Line, k string, v interface{}, alreadyImmutable bool) -// RedactStringFunc is used to redact strings as they're bing logged. +// RedactStringFunc is used to redact strings as they're being logged. // It is RedactStringFunc's responsiblity to call // -// baseLine.String(k, v) +// baseLine.String(k, v, xopbase.StringDataType) // // if it wants the value to be logged. // @@ -45,6 +45,20 @@ type RedactAnyFunc func(baseLine xopbase.Line, k string, v interface{}, alreadyI // the function call. type RedactStringFunc func(baseLine xopbase.Line, k string, v string) +// RedactErrorFunc is used to redact or format errors as they're being +// logged. It is RedactErrorFunc's responsibility to call +// +// baseLine.String(k, v.Error(), xopbase.ErrorDataType) +// +// if it wants the value to be logged. Alternatively, it could log the +// error as a model: +// +// baseLine.Any(k, v) +// +// The provided xopbase.Line may not be retained beyond the duration of +// the function call. +type RedactErrorFunc func(baseLine xopbase.Line, k string, v error) + type LogSettings struct { prefillMsg string prefillData []func(xopbase.Prefilling) @@ -54,6 +68,7 @@ type LogSettings struct { synchronousFlushWhenDone bool redactAny RedactAnyFunc redactString RedactStringFunc + redactError RedactErrorFunc } // DefaultSettings are the settings that are used if no setting changes @@ -190,21 +205,6 @@ func (settings LogSettings) GetMinLevel() xopnum.Level { return settings.minimumLogLevel } -// MACRO BaseDataWithType ONLY:String,Any -// SetRedactZZZFunc sets a redaction function to be used -// when Line.ZZZ() is called. -func (sub *Sub) SetRedactZZZFunc(f RedactZZZFunc) *Sub { - sub.settings.SetRedactZZZFunc(f) - return sub -} - -// MACRO BaseDataWithType ONLY:String,Any -// SetRedactZZZFunc sets a redaction function to be used -// when Line.ZZZ() is called. -func (settings *LogSettings) SetRedactZZZFunc(f RedactZZZFunc) { - settings.redactZZZ = f -} - // TagLinesWithSpanSequence controls if the span sequence // indicator (see Fork() and Step()) should be included in // the prefill data on each line. @@ -249,7 +249,7 @@ func (log *Log) sendPrefill() { f(prefilling) } if log.settings.tagLinesWithSpanSequence { - prefilling.String(xopconst.SpanSequenceCode.Key(), log.span.seed.spanSequenceCode) + prefilling.String(xopconst.SpanSequenceCode.Key(), log.span.seed.spanSequenceCode, xopbase.StringDataType) } log.prefilled = prefilling.PrefillComplete(log.settings.prefillMsg) } @@ -282,11 +282,29 @@ func (settings *LogSettings) PrefillEnum(k *xopat.EnumAttribute, v xopat.Enum) { }) } +// PrefillError is used to set a data element that is included on every log +// line. Errors will always be formatted with v.Error(). Redaction is +// not supported. +func (sub *Sub) PrefillError(k string, v error) *Sub { + sub.settings.PrefillError(k, v) + return sub +} + +// PrefillError is used to set a data element that is included on every log +// line. Errors will always be formatted with v.Error(). Redaction is +// not supported. +func (settings *LogSettings) PrefillError(k string, v error) { + settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { + line.String(k, v.Error(), xopbase.ErrorDataType) + }) +} + // PrefillAny is used to set a data element that is included on every log // line. Values provided with PrefillAny will be copied // using https://github.com/mohae/deepcopy 's Copy(). // PrefillAny is not threadsafe with respect to other calls on the same *Sub. // Should not be used after Step(), Fork(), or Log() is called. +// Redaction is not supported. func (sub *Sub) PrefillAny(k string, v interface{}) *Sub { sub.settings.PrefillAny(k, v) return sub @@ -297,17 +315,35 @@ func (sub *Sub) PrefillAny(k string, v interface{}) *Sub { // using https://github.com/mohae/deepcopy 's Copy(). // PrefillAny is not threadsafe with respect to other calls on the same *Sub. // Should not be used after Step(), Fork(), or Log() is called. +// Redaction is not supported. func (settings *LogSettings) PrefillAny(k string, v interface{}) { settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { line.Any(k, v) }) } +// PrefillFloat32 is used to set a data element that is included on every log +// line. +// PrefillFloat32 is not threadsafe with respect to other calls on the same *Sub. +// Should not be used after Step(), Fork(), or Log() is called. +func (sub *Sub) PrefillFloat32(k string, v float32) *Sub { + sub.settings.PrefillFloat32(k, v) + return sub +} +func (settings *LogSettings) PrefillFloat32(k string, v float32) { + settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { + line.Float64(k, float64(v), xopbase.Float32DataType) + }) +} + // MACRO BaseDataWithoutType SKIP:Any // PrefillZZZ is used to set a data element that is included on every log // line. // PrefillZZZ is not threadsafe with respect to other calls on the same *Sub. // Should not be used after Step(), Fork(), or Log() is called. +//CONDITIONAL ONLY:String +// Redaction is not supported. +//END CONDITIONAL func (sub *Sub) PrefillZZZ(k string, v zzz) *Sub { sub.settings.PrefillZZZ(k, v) return sub @@ -363,16 +399,17 @@ func (settings *LogSettings) PrefillZZZ(k string, v zzz) { }) } -// PrefillFloat32 is used to set a data element that is included on every log -// line. -// PrefillFloat32 is not threadsafe with respect to other calls on the same *Sub. -// Should not be used after Step(), Fork(), or Log() is called. -func (sub *Sub) PrefillFloat32(k string, v float32) *Sub { - sub.settings.PrefillFloat32(k, v) +// MACRO AllData ONLY:String,Any,Error +// SetRedactZZZFunc sets a redaction function to be used +// when Line.ZZZ() is called. +func (sub *Sub) SetRedactZZZFunc(f RedactZZZFunc) *Sub { + sub.settings.SetRedactZZZFunc(f) return sub } -func (settings *LogSettings) PrefillFloat32(k string, v float32) { - settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) { - line.Float64(k, float64(v), xopbase.Float32DataType) - }) + +// MACRO AllData ONLY:String,Any,Error +// SetRedactZZZFunc sets a redaction function to be used +// when Line.ZZZ() is called. +func (settings *LogSettings) SetRedactZZZFunc(f RedactZZZFunc) { + settings.redactZZZ = f } diff --git a/tools/xopzzz/xopzzz.go b/tools/xopzzz/xopzzz.go index 6f03df2d..c5cfa451 100644 --- a/tools/xopzzz/xopzzz.go +++ b/tools/xopzzz/xopzzz.go @@ -72,7 +72,7 @@ var macros = map[string]map[string]string{ "Uint16": "uint16", "Uint32": "uint32", }, - // BaseData are the data types that are supported on a per-line basis + // BaseData are the data types that are supported on a per-line basis in xopbase.Line // Note: Enum is not included since it needs special handling every time "BaseData": { "Int64": "int64", @@ -81,17 +81,14 @@ var macros = map[string]map[string]string{ "Bool": "bool", "Any": "interface{}", "Link": "trace.Trace", - "Error": "error", "Time": "time.Time", "Duration": "time.Duration", "Float64": "float64", }, "BaseDataWithoutType": { - "String": "string", "Bool": "bool", "Any": "interface{}", "Link": "trace.Trace", - "Error": "error", "Time": "time.Time", "Duration": "time.Duration", }, @@ -99,6 +96,7 @@ var macros = map[string]map[string]string{ "Int64": "int64", "Uint64": "uint64", "Float64": "float64", + "String": "string", }, "AllData": { "Int": "int", @@ -120,6 +118,7 @@ var macros = map[string]map[string]string{ "Float64": "float64", "Float32": "float32", "Time": "time.Time", + "Stringer": "fmt.Stringer", }, "HexBytes": { "HexBytes1": "1", diff --git a/xopbase/base.go b/xopbase/base.go index d0de2c84..31ca0ec1 100644 --- a/xopbase/base.go +++ b/xopbase/base.go @@ -156,7 +156,6 @@ type ObjectParts interface { Enum(*xopat.EnumAttribute, xopat.Enum) // TODO: split the above off as "BasicObjectParts" // TODO: Table(string, table) - // TODO: SubObject(string) SubObject // TODO: Encoded(name string, elementName string, encoder Encoder, data interface{}) // TODO: PreEncodedBytes(name string, elementName string, mimeType string, data []byte) // TODO: PreEncodedText(name string, elementName string, mimeType string, data string) @@ -164,23 +163,16 @@ type ObjectParts interface { Float64(string, float64, DataType) Int64(string, int64, DataType) + String(string, string, DataType) Uint64(string, uint64, DataType) Any(string, interface{}) Bool(string, bool) Duration(string, time.Duration) - Error(string, error) Link(string, trace.Trace) - String(string, string) Time(string, time.Time) } -// TODO -type SubObject interface { - ObjectParts - Complete() -} - // TODO type Encoder interface { MimeType() string @@ -208,6 +200,7 @@ const ( Int8DataType DataType = iota LinkDataType DataType = iota StringDataType DataType = iota + StringerDataType DataType = iota TimeDataType DataType = iota UintDataType DataType = iota Uint16DataType DataType = iota @@ -227,6 +220,7 @@ const ( Int8ArrayDataType DataType = iota LinkArrayDataType DataType = iota StringArrayDataType DataType = iota + StringerArrayDataType DataType = iota TimeArrayDataType DataType = iota UintArrayDataType DataType = iota Uint16ArrayDataType DataType = iota diff --git a/xopbase/base.zzzgo b/xopbase/base.zzzgo index 44bee2dc..eeeedfab 100644 --- a/xopbase/base.zzzgo +++ b/xopbase/base.zzzgo @@ -141,7 +141,6 @@ type ObjectParts interface { Enum(*xopat.EnumAttribute, xopat.Enum) // TODO: split the above off as "BasicObjectParts" // TODO: Table(string, table) - // TODO: SubObject(string) SubObject // TODO: Encoded(name string, elementName string, encoder Encoder, data interface{}) // TODO: PreEncodedBytes(name string, elementName string, mimeType string, data []byte) // TODO: PreEncodedText(name string, elementName string, mimeType string, data string) @@ -154,12 +153,6 @@ type ObjectParts interface { ZZZ(string, zzz) } -// TODO -type SubObject interface { - ObjectParts - Complete() -} - // TODO type Encoder interface { MimeType() string diff --git a/xopbase/datatype_enumer.go b/xopbase/datatype_enumer.go index 75bf984b..163bddc8 100644 --- a/xopbase/datatype_enumer.go +++ b/xopbase/datatype_enumer.go @@ -9,11 +9,11 @@ import ( "strings" ) -const _DataTypeName = "EnumDataTypeEnumArrayDataTypeAnyDataTypeBoolDataTypeDurationDataTypeErrorDataTypeFloat32DataTypeFloat64DataTypeIntDataTypeInt16DataTypeInt32DataTypeInt64DataTypeInt8DataTypeLinkDataTypeStringDataTypeTimeDataTypeUintDataTypeUint16DataTypeUint32DataTypeUint64DataTypeUint8DataTypeAnyArrayDataTypeBoolArrayDataTypeDurationArrayDataTypeErrorArrayDataTypeFloat32ArrayDataTypeFloat64ArrayDataTypeIntArrayDataTypeInt16ArrayDataTypeInt32ArrayDataTypeInt64ArrayDataTypeInt8ArrayDataTypeLinkArrayDataTypeStringArrayDataTypeTimeArrayDataTypeUintArrayDataTypeUint16ArrayDataTypeUint32ArrayDataTypeUint64ArrayDataTypeUint8ArrayDataType" +const _DataTypeName = "EnumDataTypeEnumArrayDataTypeAnyDataTypeBoolDataTypeDurationDataTypeErrorDataTypeFloat32DataTypeFloat64DataTypeIntDataTypeInt16DataTypeInt32DataTypeInt64DataTypeInt8DataTypeLinkDataTypeStringDataTypeStringerDataTypeTimeDataTypeUintDataTypeUint16DataTypeUint32DataTypeUint64DataTypeUint8DataTypeAnyArrayDataTypeBoolArrayDataTypeDurationArrayDataTypeErrorArrayDataTypeFloat32ArrayDataTypeFloat64ArrayDataTypeIntArrayDataTypeInt16ArrayDataTypeInt32ArrayDataTypeInt64ArrayDataTypeInt8ArrayDataTypeLinkArrayDataTypeStringArrayDataTypeStringerArrayDataTypeTimeArrayDataTypeUintArrayDataTypeUint16ArrayDataTypeUint32ArrayDataTypeUint64ArrayDataTypeUint8ArrayDataType" -var _DataTypeIndex = [...]uint16{0, 12, 29, 40, 52, 68, 81, 96, 111, 122, 135, 148, 161, 173, 185, 199, 211, 223, 237, 251, 265, 278, 294, 311, 332, 350, 370, 390, 406, 424, 442, 460, 477, 494, 513, 530, 547, 566, 585, 604, 622} +var _DataTypeIndex = [...]uint16{0, 12, 29, 40, 52, 68, 81, 96, 111, 122, 135, 148, 161, 173, 185, 199, 215, 227, 239, 253, 267, 281, 294, 310, 327, 348, 366, 386, 406, 422, 440, 458, 476, 493, 510, 529, 550, 567, 584, 603, 622, 641, 659} -const _DataTypeLowerName = "enumdatatypeenumarraydatatypeanydatatypebooldatatypedurationdatatypeerrordatatypefloat32datatypefloat64datatypeintdatatypeint16datatypeint32datatypeint64datatypeint8datatypelinkdatatypestringdatatypetimedatatypeuintdatatypeuint16datatypeuint32datatypeuint64datatypeuint8datatypeanyarraydatatypeboolarraydatatypedurationarraydatatypeerrorarraydatatypefloat32arraydatatypefloat64arraydatatypeintarraydatatypeint16arraydatatypeint32arraydatatypeint64arraydatatypeint8arraydatatypelinkarraydatatypestringarraydatatypetimearraydatatypeuintarraydatatypeuint16arraydatatypeuint32arraydatatypeuint64arraydatatypeuint8arraydatatype" +const _DataTypeLowerName = "enumdatatypeenumarraydatatypeanydatatypebooldatatypedurationdatatypeerrordatatypefloat32datatypefloat64datatypeintdatatypeint16datatypeint32datatypeint64datatypeint8datatypelinkdatatypestringdatatypestringerdatatypetimedatatypeuintdatatypeuint16datatypeuint32datatypeuint64datatypeuint8datatypeanyarraydatatypeboolarraydatatypedurationarraydatatypeerrorarraydatatypefloat32arraydatatypefloat64arraydatatypeintarraydatatypeint16arraydatatypeint32arraydatatypeint64arraydatatypeint8arraydatatypelinkarraydatatypestringarraydatatypestringerarraydatatypetimearraydatatypeuintarraydatatypeuint16arraydatatypeuint32arraydatatypeuint64arraydatatypeuint8arraydatatype" func (i DataType) String() string { if i < 0 || i >= DataType(len(_DataTypeIndex)-1) { @@ -41,34 +41,36 @@ func _DataTypeNoOp() { _ = x[Int8DataType-(12)] _ = x[LinkDataType-(13)] _ = x[StringDataType-(14)] - _ = x[TimeDataType-(15)] - _ = x[UintDataType-(16)] - _ = x[Uint16DataType-(17)] - _ = x[Uint32DataType-(18)] - _ = x[Uint64DataType-(19)] - _ = x[Uint8DataType-(20)] - _ = x[AnyArrayDataType-(21)] - _ = x[BoolArrayDataType-(22)] - _ = x[DurationArrayDataType-(23)] - _ = x[ErrorArrayDataType-(24)] - _ = x[Float32ArrayDataType-(25)] - _ = x[Float64ArrayDataType-(26)] - _ = x[IntArrayDataType-(27)] - _ = x[Int16ArrayDataType-(28)] - _ = x[Int32ArrayDataType-(29)] - _ = x[Int64ArrayDataType-(30)] - _ = x[Int8ArrayDataType-(31)] - _ = x[LinkArrayDataType-(32)] - _ = x[StringArrayDataType-(33)] - _ = x[TimeArrayDataType-(34)] - _ = x[UintArrayDataType-(35)] - _ = x[Uint16ArrayDataType-(36)] - _ = x[Uint32ArrayDataType-(37)] - _ = x[Uint64ArrayDataType-(38)] - _ = x[Uint8ArrayDataType-(39)] + _ = x[StringerDataType-(15)] + _ = x[TimeDataType-(16)] + _ = x[UintDataType-(17)] + _ = x[Uint16DataType-(18)] + _ = x[Uint32DataType-(19)] + _ = x[Uint64DataType-(20)] + _ = x[Uint8DataType-(21)] + _ = x[AnyArrayDataType-(22)] + _ = x[BoolArrayDataType-(23)] + _ = x[DurationArrayDataType-(24)] + _ = x[ErrorArrayDataType-(25)] + _ = x[Float32ArrayDataType-(26)] + _ = x[Float64ArrayDataType-(27)] + _ = x[IntArrayDataType-(28)] + _ = x[Int16ArrayDataType-(29)] + _ = x[Int32ArrayDataType-(30)] + _ = x[Int64ArrayDataType-(31)] + _ = x[Int8ArrayDataType-(32)] + _ = x[LinkArrayDataType-(33)] + _ = x[StringArrayDataType-(34)] + _ = x[StringerArrayDataType-(35)] + _ = x[TimeArrayDataType-(36)] + _ = x[UintArrayDataType-(37)] + _ = x[Uint16ArrayDataType-(38)] + _ = x[Uint32ArrayDataType-(39)] + _ = x[Uint64ArrayDataType-(40)] + _ = x[Uint8ArrayDataType-(41)] } -var _DataTypeValues = []DataType{EnumDataType, EnumArrayDataType, AnyDataType, BoolDataType, DurationDataType, ErrorDataType, Float32DataType, Float64DataType, IntDataType, Int16DataType, Int32DataType, Int64DataType, Int8DataType, LinkDataType, StringDataType, TimeDataType, UintDataType, Uint16DataType, Uint32DataType, Uint64DataType, Uint8DataType, AnyArrayDataType, BoolArrayDataType, DurationArrayDataType, ErrorArrayDataType, Float32ArrayDataType, Float64ArrayDataType, IntArrayDataType, Int16ArrayDataType, Int32ArrayDataType, Int64ArrayDataType, Int8ArrayDataType, LinkArrayDataType, StringArrayDataType, TimeArrayDataType, UintArrayDataType, Uint16ArrayDataType, Uint32ArrayDataType, Uint64ArrayDataType, Uint8ArrayDataType} +var _DataTypeValues = []DataType{EnumDataType, EnumArrayDataType, AnyDataType, BoolDataType, DurationDataType, ErrorDataType, Float32DataType, Float64DataType, IntDataType, Int16DataType, Int32DataType, Int64DataType, Int8DataType, LinkDataType, StringDataType, StringerDataType, TimeDataType, UintDataType, Uint16DataType, Uint32DataType, Uint64DataType, Uint8DataType, AnyArrayDataType, BoolArrayDataType, DurationArrayDataType, ErrorArrayDataType, Float32ArrayDataType, Float64ArrayDataType, IntArrayDataType, Int16ArrayDataType, Int32ArrayDataType, Int64ArrayDataType, Int8ArrayDataType, LinkArrayDataType, StringArrayDataType, StringerArrayDataType, TimeArrayDataType, UintArrayDataType, Uint16ArrayDataType, Uint32ArrayDataType, Uint64ArrayDataType, Uint8ArrayDataType} var _DataTypeNameToValueMap = map[string]DataType{ _DataTypeName[0:12]: EnumDataType, @@ -101,56 +103,60 @@ var _DataTypeNameToValueMap = map[string]DataType{ _DataTypeLowerName[173:185]: LinkDataType, _DataTypeName[185:199]: StringDataType, _DataTypeLowerName[185:199]: StringDataType, - _DataTypeName[199:211]: TimeDataType, - _DataTypeLowerName[199:211]: TimeDataType, - _DataTypeName[211:223]: UintDataType, - _DataTypeLowerName[211:223]: UintDataType, - _DataTypeName[223:237]: Uint16DataType, - _DataTypeLowerName[223:237]: Uint16DataType, - _DataTypeName[237:251]: Uint32DataType, - _DataTypeLowerName[237:251]: Uint32DataType, - _DataTypeName[251:265]: Uint64DataType, - _DataTypeLowerName[251:265]: Uint64DataType, - _DataTypeName[265:278]: Uint8DataType, - _DataTypeLowerName[265:278]: Uint8DataType, - _DataTypeName[278:294]: AnyArrayDataType, - _DataTypeLowerName[278:294]: AnyArrayDataType, - _DataTypeName[294:311]: BoolArrayDataType, - _DataTypeLowerName[294:311]: BoolArrayDataType, - _DataTypeName[311:332]: DurationArrayDataType, - _DataTypeLowerName[311:332]: DurationArrayDataType, - _DataTypeName[332:350]: ErrorArrayDataType, - _DataTypeLowerName[332:350]: ErrorArrayDataType, - _DataTypeName[350:370]: Float32ArrayDataType, - _DataTypeLowerName[350:370]: Float32ArrayDataType, - _DataTypeName[370:390]: Float64ArrayDataType, - _DataTypeLowerName[370:390]: Float64ArrayDataType, - _DataTypeName[390:406]: IntArrayDataType, - _DataTypeLowerName[390:406]: IntArrayDataType, - _DataTypeName[406:424]: Int16ArrayDataType, - _DataTypeLowerName[406:424]: Int16ArrayDataType, - _DataTypeName[424:442]: Int32ArrayDataType, - _DataTypeLowerName[424:442]: Int32ArrayDataType, - _DataTypeName[442:460]: Int64ArrayDataType, - _DataTypeLowerName[442:460]: Int64ArrayDataType, - _DataTypeName[460:477]: Int8ArrayDataType, - _DataTypeLowerName[460:477]: Int8ArrayDataType, - _DataTypeName[477:494]: LinkArrayDataType, - _DataTypeLowerName[477:494]: LinkArrayDataType, - _DataTypeName[494:513]: StringArrayDataType, - _DataTypeLowerName[494:513]: StringArrayDataType, - _DataTypeName[513:530]: TimeArrayDataType, - _DataTypeLowerName[513:530]: TimeArrayDataType, - _DataTypeName[530:547]: UintArrayDataType, - _DataTypeLowerName[530:547]: UintArrayDataType, - _DataTypeName[547:566]: Uint16ArrayDataType, - _DataTypeLowerName[547:566]: Uint16ArrayDataType, - _DataTypeName[566:585]: Uint32ArrayDataType, - _DataTypeLowerName[566:585]: Uint32ArrayDataType, - _DataTypeName[585:604]: Uint64ArrayDataType, - _DataTypeLowerName[585:604]: Uint64ArrayDataType, - _DataTypeName[604:622]: Uint8ArrayDataType, - _DataTypeLowerName[604:622]: Uint8ArrayDataType, + _DataTypeName[199:215]: StringerDataType, + _DataTypeLowerName[199:215]: StringerDataType, + _DataTypeName[215:227]: TimeDataType, + _DataTypeLowerName[215:227]: TimeDataType, + _DataTypeName[227:239]: UintDataType, + _DataTypeLowerName[227:239]: UintDataType, + _DataTypeName[239:253]: Uint16DataType, + _DataTypeLowerName[239:253]: Uint16DataType, + _DataTypeName[253:267]: Uint32DataType, + _DataTypeLowerName[253:267]: Uint32DataType, + _DataTypeName[267:281]: Uint64DataType, + _DataTypeLowerName[267:281]: Uint64DataType, + _DataTypeName[281:294]: Uint8DataType, + _DataTypeLowerName[281:294]: Uint8DataType, + _DataTypeName[294:310]: AnyArrayDataType, + _DataTypeLowerName[294:310]: AnyArrayDataType, + _DataTypeName[310:327]: BoolArrayDataType, + _DataTypeLowerName[310:327]: BoolArrayDataType, + _DataTypeName[327:348]: DurationArrayDataType, + _DataTypeLowerName[327:348]: DurationArrayDataType, + _DataTypeName[348:366]: ErrorArrayDataType, + _DataTypeLowerName[348:366]: ErrorArrayDataType, + _DataTypeName[366:386]: Float32ArrayDataType, + _DataTypeLowerName[366:386]: Float32ArrayDataType, + _DataTypeName[386:406]: Float64ArrayDataType, + _DataTypeLowerName[386:406]: Float64ArrayDataType, + _DataTypeName[406:422]: IntArrayDataType, + _DataTypeLowerName[406:422]: IntArrayDataType, + _DataTypeName[422:440]: Int16ArrayDataType, + _DataTypeLowerName[422:440]: Int16ArrayDataType, + _DataTypeName[440:458]: Int32ArrayDataType, + _DataTypeLowerName[440:458]: Int32ArrayDataType, + _DataTypeName[458:476]: Int64ArrayDataType, + _DataTypeLowerName[458:476]: Int64ArrayDataType, + _DataTypeName[476:493]: Int8ArrayDataType, + _DataTypeLowerName[476:493]: Int8ArrayDataType, + _DataTypeName[493:510]: LinkArrayDataType, + _DataTypeLowerName[493:510]: LinkArrayDataType, + _DataTypeName[510:529]: StringArrayDataType, + _DataTypeLowerName[510:529]: StringArrayDataType, + _DataTypeName[529:550]: StringerArrayDataType, + _DataTypeLowerName[529:550]: StringerArrayDataType, + _DataTypeName[550:567]: TimeArrayDataType, + _DataTypeLowerName[550:567]: TimeArrayDataType, + _DataTypeName[567:584]: UintArrayDataType, + _DataTypeLowerName[567:584]: UintArrayDataType, + _DataTypeName[584:603]: Uint16ArrayDataType, + _DataTypeLowerName[584:603]: Uint16ArrayDataType, + _DataTypeName[603:622]: Uint32ArrayDataType, + _DataTypeLowerName[603:622]: Uint32ArrayDataType, + _DataTypeName[622:641]: Uint64ArrayDataType, + _DataTypeLowerName[622:641]: Uint64ArrayDataType, + _DataTypeName[641:659]: Uint8ArrayDataType, + _DataTypeLowerName[641:659]: Uint8ArrayDataType, } var _DataTypeNames = []string{ @@ -169,31 +175,33 @@ var _DataTypeNames = []string{ _DataTypeName[161:173], _DataTypeName[173:185], _DataTypeName[185:199], - _DataTypeName[199:211], - _DataTypeName[211:223], - _DataTypeName[223:237], - _DataTypeName[237:251], - _DataTypeName[251:265], - _DataTypeName[265:278], - _DataTypeName[278:294], - _DataTypeName[294:311], - _DataTypeName[311:332], - _DataTypeName[332:350], - _DataTypeName[350:370], - _DataTypeName[370:390], - _DataTypeName[390:406], - _DataTypeName[406:424], - _DataTypeName[424:442], - _DataTypeName[442:460], - _DataTypeName[460:477], - _DataTypeName[477:494], - _DataTypeName[494:513], - _DataTypeName[513:530], - _DataTypeName[530:547], - _DataTypeName[547:566], - _DataTypeName[566:585], - _DataTypeName[585:604], - _DataTypeName[604:622], + _DataTypeName[199:215], + _DataTypeName[215:227], + _DataTypeName[227:239], + _DataTypeName[239:253], + _DataTypeName[253:267], + _DataTypeName[267:281], + _DataTypeName[281:294], + _DataTypeName[294:310], + _DataTypeName[310:327], + _DataTypeName[327:348], + _DataTypeName[348:366], + _DataTypeName[366:386], + _DataTypeName[386:406], + _DataTypeName[406:422], + _DataTypeName[422:440], + _DataTypeName[440:458], + _DataTypeName[458:476], + _DataTypeName[476:493], + _DataTypeName[493:510], + _DataTypeName[510:529], + _DataTypeName[529:550], + _DataTypeName[550:567], + _DataTypeName[567:584], + _DataTypeName[584:603], + _DataTypeName[603:622], + _DataTypeName[622:641], + _DataTypeName[641:659], } // DataTypeString retrieves an enum value from the enum constants string name. diff --git a/xopjson/jsonlogger.go b/xopjson/jsonlogger.go index da87e2a1..e4506a9e 100644 --- a/xopjson/jsonlogger.go +++ b/xopjson/jsonlogger.go @@ -260,7 +260,7 @@ func (s *span) Span(_ context.Context, ts time.Time, trace trace.Bundle, name st } func (s *span) spanStartData(rq *builder) { - rq.String("span.name", s.name) + rq.stringKV("span.name", s.name) rq.Time("ts", s.startTime) } @@ -532,7 +532,7 @@ func (b *builder) AddAny(v interface{}) { if err != nil { b.B = b.B[:before] b.span.request.errorFunc(err) - b.Error("encode", err) + b.stringKV("encode", err.Error()) } else { // remove \n added by json.Encoder.Encode. So helpful! if b.B[len(b.B)-1] == '\n' { @@ -549,7 +549,6 @@ func (b *builder) Enum(k *xopat.EnumAttribute, v xopat.Enum) { } func (b *builder) AddEnum(v xopat.Enum) { - // TODO: send dictionary and numbers b.AddString(v.String()) } @@ -565,7 +564,6 @@ func (b *builder) AddTime(t time.Time) { func (b *builder) Link(k string, v trace.Trace) { b.startAttributes() - // TODO: is this the right format for links? b.AddKey(k) b.AddLink(v) } @@ -594,12 +592,16 @@ func (b *builder) Uint64(k string, v uint64, _ xopbase.DataType) { b.AddUint64(v) } -func (b *builder) String(k string, v string) { +func (b *builder) stringKV(k string, v string) { b.startAttributes() b.AddKey(k) b.AddString(v) } +func (b *builder) String(k string, v string, _ xopbase.DataType) { + b.stringKV(k, v) +} + func (b *builder) Float64(k string, v float64, _ xopbase.DataType) { b.startAttributes() b.AddKey(k) @@ -629,17 +631,6 @@ func (b *builder) AddDuration(v time.Duration) { } } -// TODO: allow custom formats -func (b *builder) Error(k string, v error) { - b.startAttributes() - b.AddKey(k) - b.AddError(v) -} - -func (b *builder) AddError(v error) { - b.AddString(v.Error()) -} - func (s *span) MetadataAny(k *xopat.AnyAttribute, v interface{}) { s.attributes.MetadataAny(k, v) } func (s *span) MetadataBool(k *xopat.BoolAttribute, v bool) { s.attributes.MetadataBool(k, v) } func (s *span) MetadataEnum(k *xopat.EnumAttribute, v xopat.Enum) { s.attributes.MetadataEnum(k, v) } diff --git a/xopjson/jsonlogger.zzzgo b/xopjson/jsonlogger.zzzgo index 125f51a5..67274f6c 100644 --- a/xopjson/jsonlogger.zzzgo +++ b/xopjson/jsonlogger.zzzgo @@ -258,7 +258,7 @@ func (s *span) Span(_ context.Context, ts time.Time, trace trace.Bundle, name st } func (s *span) spanStartData(rq *builder) { - rq.String("span.name", s.name) + rq.stringKV("span.name", s.name) rq.Time("ts", s.startTime) } @@ -530,7 +530,7 @@ func (b *builder) AddAny(v interface{}) { if err != nil { b.B = b.B[:before] b.span.request.errorFunc(err) - b.Error("encode", err) + b.stringKV("encode", err.Error()) } else { // remove \n added by json.Encoder.Encode. So helpful! if b.B[len(b.B)-1] == '\n' { @@ -547,7 +547,6 @@ func (b *builder) Enum(k *xopat.EnumAttribute, v xopat.Enum) { } func (b *builder) AddEnum(v xopat.Enum) { - // TODO: send dictionary and numbers b.AddString(v.String()) } @@ -563,7 +562,6 @@ func (b *builder) AddTime(t time.Time) { func (b *builder) Link(k string, v trace.Trace) { b.startAttributes() - // TODO: is this the right format for links? b.AddKey(k) b.AddLink(v) } @@ -592,12 +590,16 @@ func (b *builder) Uint64(k string, v uint64, _ xopbase.DataType) { b.AddUint64(v) } -func (b *builder) String(k string, v string) { +func (b *builder) stringKV(k string, v string) { b.startAttributes() b.AddKey(k) b.AddString(v) } +func (b *builder) String(k string, v string, _ xopbase.DataType) { + b.stringKV(k, v) +} + func (b *builder) Float64(k string, v float64, _ xopbase.DataType) { b.startAttributes() b.AddKey(k) @@ -627,17 +629,6 @@ func (b *builder) AddDuration(v time.Duration) { } } -// TODO: allow custom formats -func (b *builder) Error(k string, v error) { - b.startAttributes() - b.AddKey(k) - b.AddError(v) -} - -func (b *builder) AddError(v error) { - b.AddString(v.Error()) -} - // MACRO BaseAttribute func (s *span) MetadataZZZ(k *xopat.ZZZAttribute, v zzz) { s.attributes.MetadataZZZ(k, v) } diff --git a/xopjson/jsonlogger_test.go b/xopjson/jsonlogger_test.go index 8c6c81b7..51d97488 100644 --- a/xopjson/jsonlogger_test.go +++ b/xopjson/jsonlogger_test.go @@ -406,16 +406,12 @@ var xoptestConvert map[xopbase.DataType]func(interface{}) interface{} func init() { xoptestConvert = map[xopbase.DataType]func(interface{}) interface{}{ - xopbase.ErrorDataType: func(generic interface{}) interface{} { - return generic.(error).Error() - }, xopbase.LinkDataType: func(generic interface{}) interface{} { return map[string]interface{}{ "xop.link": generic.(trace.Trace).String(), } }, - xopbase.LinkArrayDataType: genArrayConvert(xopbase.LinkDataType), - xopbase.ErrorArrayDataType: genArrayConvert(xopbase.ErrorDataType), + xopbase.LinkArrayDataType: genArrayConvert(xopbase.LinkDataType), } } diff --git a/xopotel/otel.go b/xopotel/otel.go index 74fb5b74..c0666a60 100644 --- a/xopotel/otel.go +++ b/xopotel/otel.go @@ -312,10 +312,6 @@ func (builder *builder) Duration(k string, v time.Duration) { builder.attributes = append(builder.attributes, attribute.Stringer(k, v)) } -func (builder *builder) Error(k string, v error) { - builder.attributes = append(builder.attributes, attribute.String(k, v.Error())) -} - func (span *span) MetadataLink(k *xopat.LinkAttribute, v trace.Trace) { _, tmpSpan := span.logger.tracer.Start(span.ctx, k.Key(), oteltrace.WithLinks( oteltrace.Link{ @@ -354,10 +350,6 @@ func (builder *builder) Bool(k string, v bool) { builder.attributes = append(builder.attributes, attribute.Bool(k, v)) } -func (builder *builder) String(k string, v string) { - builder.attributes = append(builder.attributes, attribute.String(k, v)) -} - func (builder *builder) Float64(k string, v float64, _ xopbase.DataType) { builder.attributes = append(builder.attributes, attribute.Float64(k, v)) } @@ -366,6 +358,10 @@ func (builder *builder) Int64(k string, v int64, _ xopbase.DataType) { builder.attributes = append(builder.attributes, attribute.Int64(k, v)) } +func (builder *builder) String(k string, v string, _ xopbase.DataType) { + builder.attributes = append(builder.attributes, attribute.String(k, v)) +} + func (span *span) MetadataAny(k *xopat.AnyAttribute, v interface{}) { key := k.Key() enc, err := json.Marshal(v) diff --git a/xopotel/otel.zzzgo b/xopotel/otel.zzzgo index b8024e60..5b0633a6 100644 --- a/xopotel/otel.zzzgo +++ b/xopotel/otel.zzzgo @@ -294,10 +294,6 @@ func (builder *builder) Duration(k string, v time.Duration) { builder.attributes = append(builder.attributes, attribute.Stringer(k, v)) } -func (builder *builder) Error(k string, v error) { - builder.attributes = append(builder.attributes, attribute.String(k, v.Error())) -} - func (span *span) MetadataLink(k *xopat.LinkAttribute, v trace.Trace) { _, tmpSpan := span.logger.tracer.Start(span.ctx, k.Key(), oteltrace.WithLinks( oteltrace.Link{ @@ -332,12 +328,11 @@ func (builder *builder) Link(k string, v trace.Trace) { []string{"link", v.TraceID().String(), v.SpanID().String()})) } -// MACRO BaseData ONLY:String,Bool -func (builder *builder) ZZZ(k string, v zzz) { - builder.attributes = append(builder.attributes, attribute.ZZZ(k, v)) +func (builder *builder) Bool(k string, v bool) { + builder.attributes = append(builder.attributes, attribute.Bool(k, v)) } -// MACRO BaseData ONLY:Int64,Float64 +// MACRO BaseData ONLY:String,Int64,Float64 func (builder *builder) ZZZ(k string, v zzz, _ xopbase.DataType) { builder.attributes = append(builder.attributes, attribute.ZZZ(k, v)) } diff --git a/xopotel/otel_test.go b/xopotel/otel_test.go index c8d940d2..fa0826ac 100644 --- a/xopotel/otel_test.go +++ b/xopotel/otel_test.go @@ -372,9 +372,6 @@ var xoptestConvert map[xopbase.DataType]func(interface{}) interface{} func init() { xoptestConvert = map[xopbase.DataType]func(interface{}) interface{}{ - xopbase.ErrorDataType: func(generic interface{}) interface{} { - return generic.(error).Error() - }, xopbase.DurationDataType: func(generic interface{}) interface{} { return generic.(time.Duration).String() }, @@ -393,7 +390,6 @@ func init() { return string(enc) } }, - xopbase.ErrorArrayDataType: genArrayConvert(xopbase.ErrorDataType), xopbase.DurationArrayDataType: genArrayConvert(xopbase.DurationDataType), xopbase.AnyArrayDataType: genArrayConvert(xopbase.AnyDataType), xopbase.LinkArrayDataType: genArrayConvert(xopbase.LinkDataType), diff --git a/xoptest/testlogger.go b/xoptest/testlogger.go index 837c8d41..c63e3187 100644 --- a/xoptest/testlogger.go +++ b/xoptest/testlogger.go @@ -408,12 +408,11 @@ func (b *Builder) Link(k string, v trace.Trace) { func (b *Builder) Any(k string, v interface{}) { b.any(k, v, xopbase.AnyDataType) } func (b *Builder) Bool(k string, v bool) { b.any(k, v, xopbase.BoolDataType) } func (b *Builder) Duration(k string, v time.Duration) { b.any(k, v, xopbase.DurationDataType) } -func (b *Builder) Error(k string, v error) { b.any(k, v, xopbase.ErrorDataType) } -func (b *Builder) String(k string, v string) { b.any(k, v, xopbase.StringDataType) } func (b *Builder) Time(k string, v time.Time) { b.any(k, v, xopbase.TimeDataType) } func (b *Builder) Float64(k string, v float64, dt xopbase.DataType) { b.any(k, v, dt) } func (b *Builder) Int64(k string, v int64, dt xopbase.DataType) { b.any(k, v, dt) } +func (b *Builder) String(k string, v string, dt xopbase.DataType) { b.any(k, v, dt) } func (b *Builder) Uint64(k string, v uint64, dt xopbase.DataType) { b.any(k, v, dt) } func (s *Span) MetadataAny(k *xopat.AnyAttribute, v interface{}) { diff --git a/xoputil/skip.go b/xoputil/skip.go index 258078a1..4c7c0c9f 100644 --- a/xoputil/skip.go +++ b/xoputil/skip.go @@ -26,11 +26,10 @@ func (_ skipLine) Template(string) {} func (_ skipLine) Any(string, interface{}) {} func (_ skipLine) Bool(string, bool) {} func (_ skipLine) Duration(string, time.Duration) {} -func (_ skipLine) Error(string, error) {} func (_ skipLine) Link(string, trace.Trace) {} -func (_ skipLine) String(string, string) {} func (_ skipLine) Time(string, time.Time) {} func (_ skipLine) Float64(string, float64, xopbase.DataType) {} func (_ skipLine) Int64(string, int64, xopbase.DataType) {} +func (_ skipLine) String(string, string, xopbase.DataType) {} func (_ skipLine) Uint64(string, uint64, xopbase.DataType) {}