From 3a74a188be3d9b8c5edfda3422419b8b82efeb06 Mon Sep 17 00:00:00 2001 From: Matthew Li Date: Fri, 25 Oct 2024 14:29:02 -0400 Subject: [PATCH] updating encoder to omitempty for spanlinks in ddtrace.span --- ddtrace/tracer/civisibility_tslv_msgp.go | 28 +- ddtrace/tracer/span.go | 2 +- ddtrace/tracer/span_msgp.go | 39 +- ddtrace/tracer/stats_msgp.go | 758 +++++++++++++++++++++++ ddtrace/tracer/stats_payload_msgp.go | 4 - ddtrace/tracer/textmap.go | 18 +- ddtrace/tracer/textmap_test.go | 2 +- 7 files changed, 805 insertions(+), 46 deletions(-) create mode 100644 ddtrace/tracer/stats_msgp.go diff --git a/ddtrace/tracer/civisibility_tslv_msgp.go b/ddtrace/tracer/civisibility_tslv_msgp.go index 63fa4b8499..37c4f06a52 100644 --- a/ddtrace/tracer/civisibility_tslv_msgp.go +++ b/ddtrace/tracer/civisibility_tslv_msgp.go @@ -497,25 +497,25 @@ func (z *tslvSpan) DecodeMsg(dc *msgp.Reader) (err error) { case "test_session_id": z.SessionID, err = dc.ReadUint64() if err != nil { - err = msgp.WrapError(err, "SessionId") + err = msgp.WrapError(err, "SessionID") return } case "test_module_id": z.ModuleID, err = dc.ReadUint64() if err != nil { - err = msgp.WrapError(err, "ModuleId") + err = msgp.WrapError(err, "ModuleID") return } case "test_suite_id": z.SuiteID, err = dc.ReadUint64() if err != nil { - err = msgp.WrapError(err, "SuiteId") + err = msgp.WrapError(err, "SuiteID") return } case "itr_correlation_id": z.CorrelationID, err = dc.ReadString() if err != nil { - err = msgp.WrapError(err, "CorrelationId") + err = msgp.WrapError(err, "CorrelationID") return } case "name": @@ -651,7 +651,7 @@ func (z *tslvSpan) DecodeMsg(dc *msgp.Reader) (err error) { // EncodeMsg implements msgp.Encodable func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { - // omitempty: check for empty values + // check for omitted fields zb0001Len := uint32(16) var zb0001Mask uint16 /* 16 bits */ _ = zb0001Mask @@ -699,7 +699,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { if zb0001Len == 0 { return } - if (zb0001Mask & 0x1) == 0 { // if not empty + if (zb0001Mask & 0x1) == 0 { // if not omitted // write "test_session_id" err = en.Append(0xaf, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64) if err != nil { @@ -711,7 +711,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { return } } - if (zb0001Mask & 0x2) == 0 { // if not empty + if (zb0001Mask & 0x2) == 0 { // if not omitted // write "test_module_id" err = en.Append(0xae, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x69, 0x64) if err != nil { @@ -723,7 +723,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { return } } - if (zb0001Mask & 0x4) == 0 { // if not empty + if (zb0001Mask & 0x4) == 0 { // if not omitted // write "test_suite_id" err = en.Append(0xad, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x75, 0x69, 0x74, 0x65, 0x5f, 0x69, 0x64) if err != nil { @@ -735,7 +735,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { return } } - if (zb0001Mask & 0x8) == 0 { // if not empty + if (zb0001Mask & 0x8) == 0 { // if not omitted // write "itr_correlation_id" err = en.Append(0xb2, 0x69, 0x74, 0x72, 0x5f, 0x63, 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64) if err != nil { @@ -807,7 +807,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Duration") return } - if (zb0001Mask & 0x400) == 0 { // if not empty + if (zb0001Mask & 0x400) == 0 { // if not omitted // write "span_id" err = en.Append(0xa7, 0x73, 0x70, 0x61, 0x6e, 0x5f, 0x69, 0x64) if err != nil { @@ -819,7 +819,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { return } } - if (zb0001Mask & 0x800) == 0 { // if not empty + if (zb0001Mask & 0x800) == 0 { // if not omitted // write "trace_id" err = en.Append(0xa8, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64) if err != nil { @@ -831,7 +831,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { return } } - if (zb0001Mask & 0x1000) == 0 { // if not empty + if (zb0001Mask & 0x1000) == 0 { // if not omitted // write "parent_id" err = en.Append(0xa9, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64) if err != nil { @@ -853,7 +853,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Error") return } - if (zb0001Mask & 0x4000) == 0 { // if not empty + if (zb0001Mask & 0x4000) == 0 { // if not omitted // write "meta" err = en.Append(0xa4, 0x6d, 0x65, 0x74, 0x61) if err != nil { @@ -877,7 +877,7 @@ func (z *tslvSpan) EncodeMsg(en *msgp.Writer) (err error) { } } } - if (zb0001Mask & 0x8000) == 0 { // if not empty + if (zb0001Mask & 0x8000) == 0 { // if not omitted // write "metrics" err = en.Append(0xa7, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73) if err != nil { diff --git a/ddtrace/tracer/span.go b/ddtrace/tracer/span.go index c37af7d5c4..73b3070ad8 100644 --- a/ddtrace/tracer/span.go +++ b/ddtrace/tracer/span.go @@ -78,7 +78,7 @@ type span struct { TraceID uint64 `msg:"trace_id"` // lower 64-bits of the root span identifier ParentID uint64 `msg:"parent_id"` // identifier of the span's direct parent Error int32 `msg:"error"` // error status of the span; 0 means no errors - SpanLinks []ddtrace.SpanLink `msg:"span_links"` // links to other spans + SpanLinks []ddtrace.SpanLink `msg:"span_links,omitempty"` // links to other spans goExecTraced bool `msg:"-"` noDebugStack bool `msg:"-"` // disables debug stack traces diff --git a/ddtrace/tracer/span_msgp.go b/ddtrace/tracer/span_msgp.go index c6cb8274a7..c4a65ef723 100644 --- a/ddtrace/tracer/span_msgp.go +++ b/ddtrace/tracer/span_msgp.go @@ -4,7 +4,6 @@ package tracer import ( "github.com/tinylib/msgp/msgp" - "gopkg.in/DataDog/dd-trace-go.v1/ddtrace" ) @@ -273,7 +272,7 @@ func (z *span) DecodeMsg(dc *msgp.Reader) (err error) { // EncodeMsg implements msgp.Encodable func (z *span) EncodeMsg(en *msgp.Writer) (err error) { - // omitempty: check for empty values + // check for omitted fields zb0001Len := uint32(14) var zb0001Mask uint16 /* 14 bits */ _ = zb0001Mask @@ -285,6 +284,10 @@ func (z *span) EncodeMsg(en *msgp.Writer) (err error) { zb0001Len-- zb0001Mask |= 0x100 } + if z.SpanLinks == nil { + zb0001Len-- + zb0001Mask |= 0x2000 + } // variable map header, size zb0001Len err = en.Append(0x80 | uint8(zb0001Len)) if err != nil { @@ -353,7 +356,7 @@ func (z *span) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Duration") return } - if (zb0001Mask & 0x40) == 0 { // if not empty + if (zb0001Mask & 0x40) == 0 { // if not omitted // write "meta" err = en.Append(0xa4, 0x6d, 0x65, 0x74, 0x61) if err != nil { @@ -387,7 +390,7 @@ func (z *span) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "MetaStruct") return } - if (zb0001Mask & 0x100) == 0 { // if not empty + if (zb0001Mask & 0x100) == 0 { // if not omitted // write "metrics" err = en.Append(0xa7, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73) if err != nil { @@ -451,22 +454,24 @@ func (z *span) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Error") return } - // write "span_links" - err = en.Append(0xaa, 0x73, 0x70, 0x61, 0x6e, 0x5f, 0x6c, 0x69, 0x6e, 0x6b, 0x73) - if err != nil { - return - } - err = en.WriteArrayHeader(uint32(len(z.SpanLinks))) - if err != nil { - err = msgp.WrapError(err, "SpanLinks") - return - } - for za0005 := range z.SpanLinks { - err = z.SpanLinks[za0005].EncodeMsg(en) + if (zb0001Mask & 0x2000) == 0 { // if not omitted + // write "span_links" + err = en.Append(0xaa, 0x73, 0x70, 0x61, 0x6e, 0x5f, 0x6c, 0x69, 0x6e, 0x6b, 0x73) + if err != nil { + return + } + err = en.WriteArrayHeader(uint32(len(z.SpanLinks))) if err != nil { - err = msgp.WrapError(err, "SpanLinks", za0005) + err = msgp.WrapError(err, "SpanLinks") return } + for za0005 := range z.SpanLinks { + err = z.SpanLinks[za0005].EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "SpanLinks", za0005) + return + } + } } return } diff --git a/ddtrace/tracer/stats_msgp.go b/ddtrace/tracer/stats_msgp.go new file mode 100644 index 0000000000..5d4917e2a3 --- /dev/null +++ b/ddtrace/tracer/stats_msgp.go @@ -0,0 +1,758 @@ +package tracer + +// Code generated by github.com/tinylib/msgp DO NOT EDIT. + +import ( + "github.com/DataDog/sketches-go/ddsketch" + "github.com/tinylib/msgp/msgp" +) + +// DecodeMsg implements msgp.Decodable +func (z *aggregableSpan) DecodeMsg(dc *msgp.Reader) (err error) { + var field []byte + _ = field + var zb0001 uint32 + zb0001, err = dc.ReadMapHeader() + if err != nil { + err = msgp.WrapError(err) + return + } + for zb0001 > 0 { + zb0001-- + field, err = dc.ReadMapKeyPtr() + if err != nil { + err = msgp.WrapError(err) + return + } + switch msgp.UnsafeString(field) { + case "key": + err = z.key.DecodeMsg(dc) + if err != nil { + err = msgp.WrapError(err, "key") + return + } + case "Start": + z.Start, err = dc.ReadInt64() + if err != nil { + err = msgp.WrapError(err, "Start") + return + } + case "Duration": + z.Duration, err = dc.ReadInt64() + if err != nil { + err = msgp.WrapError(err, "Duration") + return + } + case "Error": + z.Error, err = dc.ReadInt32() + if err != nil { + err = msgp.WrapError(err, "Error") + return + } + case "TopLevel": + z.TopLevel, err = dc.ReadBool() + if err != nil { + err = msgp.WrapError(err, "TopLevel") + return + } + default: + err = dc.Skip() + if err != nil { + err = msgp.WrapError(err) + return + } + } + } + return +} + +// EncodeMsg implements msgp.Encodable +func (z *aggregableSpan) EncodeMsg(en *msgp.Writer) (err error) { + // map header, size 5 + // write "key" + err = en.Append(0x85, 0xa3, 0x6b, 0x65, 0x79) + if err != nil { + return + } + err = z.key.EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "key") + return + } + // write "Start" + err = en.Append(0xa5, 0x53, 0x74, 0x61, 0x72, 0x74) + if err != nil { + return + } + err = en.WriteInt64(z.Start) + if err != nil { + err = msgp.WrapError(err, "Start") + return + } + // write "Duration" + err = en.Append(0xa8, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e) + if err != nil { + return + } + err = en.WriteInt64(z.Duration) + if err != nil { + err = msgp.WrapError(err, "Duration") + return + } + // write "Error" + err = en.Append(0xa5, 0x45, 0x72, 0x72, 0x6f, 0x72) + if err != nil { + return + } + err = en.WriteInt32(z.Error) + if err != nil { + err = msgp.WrapError(err, "Error") + return + } + // write "TopLevel" + err = en.Append(0xa8, 0x54, 0x6f, 0x70, 0x4c, 0x65, 0x76, 0x65, 0x6c) + if err != nil { + return + } + err = en.WriteBool(z.TopLevel) + if err != nil { + err = msgp.WrapError(err, "TopLevel") + return + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *aggregableSpan) Msgsize() (s int) { + s = 1 + 4 + z.key.Msgsize() + 6 + msgp.Int64Size + 9 + msgp.Int64Size + 6 + msgp.Int32Size + 9 + msgp.BoolSize + return +} + +// DecodeMsg implements msgp.Decodable +func (z *aggregation) DecodeMsg(dc *msgp.Reader) (err error) { + var field []byte + _ = field + var zb0001 uint32 + zb0001, err = dc.ReadMapHeader() + if err != nil { + err = msgp.WrapError(err) + return + } + for zb0001 > 0 { + zb0001-- + field, err = dc.ReadMapKeyPtr() + if err != nil { + err = msgp.WrapError(err) + return + } + switch msgp.UnsafeString(field) { + case "Name": + z.Name, err = dc.ReadString() + if err != nil { + err = msgp.WrapError(err, "Name") + return + } + case "Type": + z.Type, err = dc.ReadString() + if err != nil { + err = msgp.WrapError(err, "Type") + return + } + case "Resource": + z.Resource, err = dc.ReadString() + if err != nil { + err = msgp.WrapError(err, "Resource") + return + } + case "Service": + z.Service, err = dc.ReadString() + if err != nil { + err = msgp.WrapError(err, "Service") + return + } + case "StatusCode": + z.StatusCode, err = dc.ReadUint32() + if err != nil { + err = msgp.WrapError(err, "StatusCode") + return + } + case "Synthetics": + z.Synthetics, err = dc.ReadBool() + if err != nil { + err = msgp.WrapError(err, "Synthetics") + return + } + case "IsTraceRoot": + { + var zb0002 int32 + zb0002, err = dc.ReadInt32() + if err != nil { + err = msgp.WrapError(err, "IsTraceRoot") + return + } + z.IsTraceRoot = trilean(zb0002) + } + default: + err = dc.Skip() + if err != nil { + err = msgp.WrapError(err) + return + } + } + } + return +} + +// EncodeMsg implements msgp.Encodable +func (z *aggregation) EncodeMsg(en *msgp.Writer) (err error) { + // map header, size 7 + // write "Name" + err = en.Append(0x87, 0xa4, 0x4e, 0x61, 0x6d, 0x65) + if err != nil { + return + } + err = en.WriteString(z.Name) + if err != nil { + err = msgp.WrapError(err, "Name") + return + } + // write "Type" + err = en.Append(0xa4, 0x54, 0x79, 0x70, 0x65) + if err != nil { + return + } + err = en.WriteString(z.Type) + if err != nil { + err = msgp.WrapError(err, "Type") + return + } + // write "Resource" + err = en.Append(0xa8, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65) + if err != nil { + return + } + err = en.WriteString(z.Resource) + if err != nil { + err = msgp.WrapError(err, "Resource") + return + } + // write "Service" + err = en.Append(0xa7, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65) + if err != nil { + return + } + err = en.WriteString(z.Service) + if err != nil { + err = msgp.WrapError(err, "Service") + return + } + // write "StatusCode" + err = en.Append(0xaa, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65) + if err != nil { + return + } + err = en.WriteUint32(z.StatusCode) + if err != nil { + err = msgp.WrapError(err, "StatusCode") + return + } + // write "Synthetics" + err = en.Append(0xaa, 0x53, 0x79, 0x6e, 0x74, 0x68, 0x65, 0x74, 0x69, 0x63, 0x73) + if err != nil { + return + } + err = en.WriteBool(z.Synthetics) + if err != nil { + err = msgp.WrapError(err, "Synthetics") + return + } + // write "IsTraceRoot" + err = en.Append(0xab, 0x49, 0x73, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x6f, 0x6f, 0x74) + if err != nil { + return + } + err = en.WriteInt32(int32(z.IsTraceRoot)) + if err != nil { + err = msgp.WrapError(err, "IsTraceRoot") + return + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *aggregation) Msgsize() (s int) { + s = 1 + 5 + msgp.StringPrefixSize + len(z.Name) + 5 + msgp.StringPrefixSize + len(z.Type) + 9 + msgp.StringPrefixSize + len(z.Resource) + 8 + msgp.StringPrefixSize + len(z.Service) + 11 + msgp.Uint32Size + 11 + msgp.BoolSize + 12 + msgp.Int32Size + return +} + +// DecodeMsg implements msgp.Decodable +func (z *concentrator) DecodeMsg(dc *msgp.Reader) (err error) { + var field []byte + _ = field + var zb0001 uint32 + zb0001, err = dc.ReadMapHeader() + if err != nil { + err = msgp.WrapError(err) + return + } + for zb0001 > 0 { + zb0001-- + field, err = dc.ReadMapKeyPtr() + if err != nil { + err = msgp.WrapError(err) + return + } + switch msgp.UnsafeString(field) { + case "mu": + err = z.mu.DecodeMsg(dc) + if err != nil { + err = msgp.WrapError(err, "mu") + return + } + case "stopped": + z.stopped, err = dc.ReadUint32() + if err != nil { + err = msgp.WrapError(err, "stopped") + return + } + case "wg": + err = z.wg.DecodeMsg(dc) + if err != nil { + err = msgp.WrapError(err, "wg") + return + } + case "bucketSize": + z.bucketSize, err = dc.ReadInt64() + if err != nil { + err = msgp.WrapError(err, "bucketSize") + return + } + case "cfg": + if dc.IsNil() { + err = dc.ReadNil() + if err != nil { + err = msgp.WrapError(err, "cfg") + return + } + z.cfg = nil + } else { + if z.cfg == nil { + z.cfg = new(config) + } + err = z.cfg.DecodeMsg(dc) + if err != nil { + err = msgp.WrapError(err, "cfg") + return + } + } + case "statsdClient": + err = z.statsdClient.DecodeMsg(dc) + if err != nil { + err = msgp.WrapError(err, "statsdClient") + return + } + default: + err = dc.Skip() + if err != nil { + err = msgp.WrapError(err) + return + } + } + } + return +} + +// EncodeMsg implements msgp.Encodable +func (z *concentrator) EncodeMsg(en *msgp.Writer) (err error) { + // map header, size 6 + // write "mu" + err = en.Append(0x86, 0xa2, 0x6d, 0x75) + if err != nil { + return + } + err = z.mu.EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "mu") + return + } + // write "stopped" + err = en.Append(0xa7, 0x73, 0x74, 0x6f, 0x70, 0x70, 0x65, 0x64) + if err != nil { + return + } + err = en.WriteUint32(z.stopped) + if err != nil { + err = msgp.WrapError(err, "stopped") + return + } + // write "wg" + err = en.Append(0xa2, 0x77, 0x67) + if err != nil { + return + } + err = z.wg.EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "wg") + return + } + // write "bucketSize" + err = en.Append(0xaa, 0x62, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x69, 0x7a, 0x65) + if err != nil { + return + } + err = en.WriteInt64(z.bucketSize) + if err != nil { + err = msgp.WrapError(err, "bucketSize") + return + } + // write "cfg" + err = en.Append(0xa3, 0x63, 0x66, 0x67) + if err != nil { + return + } + if z.cfg == nil { + err = en.WriteNil() + if err != nil { + return + } + } else { + err = z.cfg.EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "cfg") + return + } + } + // write "statsdClient" + err = en.Append(0xac, 0x73, 0x74, 0x61, 0x74, 0x73, 0x64, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74) + if err != nil { + return + } + err = z.statsdClient.EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "statsdClient") + return + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *concentrator) Msgsize() (s int) { + s = 1 + 3 + z.mu.Msgsize() + 8 + msgp.Uint32Size + 3 + z.wg.Msgsize() + 11 + msgp.Int64Size + 4 + if z.cfg == nil { + s += msgp.NilSize + } else { + s += z.cfg.Msgsize() + } + s += 13 + z.statsdClient.Msgsize() + return +} + +// DecodeMsg implements msgp.Decodable +func (z *rawBucket) DecodeMsg(dc *msgp.Reader) (err error) { + var field []byte + _ = field + var zb0001 uint32 + zb0001, err = dc.ReadMapHeader() + if err != nil { + err = msgp.WrapError(err) + return + } + for zb0001 > 0 { + zb0001-- + field, err = dc.ReadMapKeyPtr() + if err != nil { + err = msgp.WrapError(err) + return + } + switch msgp.UnsafeString(field) { + case "start": + z.start, err = dc.ReadUint64() + if err != nil { + err = msgp.WrapError(err, "start") + return + } + case "duration": + z.duration, err = dc.ReadUint64() + if err != nil { + err = msgp.WrapError(err, "duration") + return + } + default: + err = dc.Skip() + if err != nil { + err = msgp.WrapError(err) + return + } + } + } + return +} + +// EncodeMsg implements msgp.Encodable +func (z rawBucket) EncodeMsg(en *msgp.Writer) (err error) { + // map header, size 2 + // write "start" + err = en.Append(0x82, 0xa5, 0x73, 0x74, 0x61, 0x72, 0x74) + if err != nil { + return + } + err = en.WriteUint64(z.start) + if err != nil { + err = msgp.WrapError(err, "start") + return + } + // write "duration" + err = en.Append(0xa8, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e) + if err != nil { + return + } + err = en.WriteUint64(z.duration) + if err != nil { + err = msgp.WrapError(err, "duration") + return + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z rawBucket) Msgsize() (s int) { + s = 1 + 6 + msgp.Uint64Size + 9 + msgp.Uint64Size + return +} + +// DecodeMsg implements msgp.Decodable +func (z *rawGroupedStats) DecodeMsg(dc *msgp.Reader) (err error) { + var field []byte + _ = field + var zb0001 uint32 + zb0001, err = dc.ReadMapHeader() + if err != nil { + err = msgp.WrapError(err) + return + } + for zb0001 > 0 { + zb0001-- + field, err = dc.ReadMapKeyPtr() + if err != nil { + err = msgp.WrapError(err) + return + } + switch msgp.UnsafeString(field) { + case "hits": + z.hits, err = dc.ReadUint64() + if err != nil { + err = msgp.WrapError(err, "hits") + return + } + case "topLevelHits": + z.topLevelHits, err = dc.ReadUint64() + if err != nil { + err = msgp.WrapError(err, "topLevelHits") + return + } + case "errors": + z.errors, err = dc.ReadUint64() + if err != nil { + err = msgp.WrapError(err, "errors") + return + } + case "duration": + z.duration, err = dc.ReadUint64() + if err != nil { + err = msgp.WrapError(err, "duration") + return + } + case "okDistribution": + if dc.IsNil() { + err = dc.ReadNil() + if err != nil { + err = msgp.WrapError(err, "okDistribution") + return + } + z.okDistribution = nil + } else { + if z.okDistribution == nil { + z.okDistribution = new(ddsketch.DDSketch) + } + err = z.okDistribution.DecodeMsg(dc) + if err != nil { + err = msgp.WrapError(err, "okDistribution") + return + } + } + case "errDistribution": + if dc.IsNil() { + err = dc.ReadNil() + if err != nil { + err = msgp.WrapError(err, "errDistribution") + return + } + z.errDistribution = nil + } else { + if z.errDistribution == nil { + z.errDistribution = new(ddsketch.DDSketch) + } + err = z.errDistribution.DecodeMsg(dc) + if err != nil { + err = msgp.WrapError(err, "errDistribution") + return + } + } + case "IsTraceRoot": + { + var zb0002 int32 + zb0002, err = dc.ReadInt32() + if err != nil { + err = msgp.WrapError(err, "IsTraceRoot") + return + } + z.IsTraceRoot = trilean(zb0002) + } + default: + err = dc.Skip() + if err != nil { + err = msgp.WrapError(err) + return + } + } + } + return +} + +// EncodeMsg implements msgp.Encodable +func (z *rawGroupedStats) EncodeMsg(en *msgp.Writer) (err error) { + // map header, size 7 + // write "hits" + err = en.Append(0x87, 0xa4, 0x68, 0x69, 0x74, 0x73) + if err != nil { + return + } + err = en.WriteUint64(z.hits) + if err != nil { + err = msgp.WrapError(err, "hits") + return + } + // write "topLevelHits" + err = en.Append(0xac, 0x74, 0x6f, 0x70, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x48, 0x69, 0x74, 0x73) + if err != nil { + return + } + err = en.WriteUint64(z.topLevelHits) + if err != nil { + err = msgp.WrapError(err, "topLevelHits") + return + } + // write "errors" + err = en.Append(0xa6, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73) + if err != nil { + return + } + err = en.WriteUint64(z.errors) + if err != nil { + err = msgp.WrapError(err, "errors") + return + } + // write "duration" + err = en.Append(0xa8, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e) + if err != nil { + return + } + err = en.WriteUint64(z.duration) + if err != nil { + err = msgp.WrapError(err, "duration") + return + } + // write "okDistribution" + err = en.Append(0xae, 0x6f, 0x6b, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e) + if err != nil { + return + } + if z.okDistribution == nil { + err = en.WriteNil() + if err != nil { + return + } + } else { + err = z.okDistribution.EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "okDistribution") + return + } + } + // write "errDistribution" + err = en.Append(0xaf, 0x65, 0x72, 0x72, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e) + if err != nil { + return + } + if z.errDistribution == nil { + err = en.WriteNil() + if err != nil { + return + } + } else { + err = z.errDistribution.EncodeMsg(en) + if err != nil { + err = msgp.WrapError(err, "errDistribution") + return + } + } + // write "IsTraceRoot" + err = en.Append(0xab, 0x49, 0x73, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x6f, 0x6f, 0x74) + if err != nil { + return + } + err = en.WriteInt32(int32(z.IsTraceRoot)) + if err != nil { + err = msgp.WrapError(err, "IsTraceRoot") + return + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z *rawGroupedStats) Msgsize() (s int) { + s = 1 + 5 + msgp.Uint64Size + 13 + msgp.Uint64Size + 7 + msgp.Uint64Size + 9 + msgp.Uint64Size + 15 + if z.okDistribution == nil { + s += msgp.NilSize + } else { + s += z.okDistribution.Msgsize() + } + s += 16 + if z.errDistribution == nil { + s += msgp.NilSize + } else { + s += z.errDistribution.Msgsize() + } + s += 12 + msgp.Int32Size + return +} + +// DecodeMsg implements msgp.Decodable +func (z *trilean) DecodeMsg(dc *msgp.Reader) (err error) { + { + var zb0001 int32 + zb0001, err = dc.ReadInt32() + if err != nil { + err = msgp.WrapError(err) + return + } + (*z) = trilean(zb0001) + } + return +} + +// EncodeMsg implements msgp.Encodable +func (z trilean) EncodeMsg(en *msgp.Writer) (err error) { + err = en.WriteInt32(int32(z)) + if err != nil { + err = msgp.WrapError(err) + return + } + return +} + +// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message +func (z trilean) Msgsize() (s int) { + s = msgp.Int32Size + return +} diff --git a/ddtrace/tracer/stats_payload_msgp.go b/ddtrace/tracer/stats_payload_msgp.go index 70a3a0b4c4..462e1d680a 100644 --- a/ddtrace/tracer/stats_payload_msgp.go +++ b/ddtrace/tracer/stats_payload_msgp.go @@ -1,7 +1,3 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2016 Datadog, Inc. package tracer // Code generated by github.com/tinylib/msgp DO NOT EDIT. diff --git a/ddtrace/tracer/textmap.go b/ddtrace/tracer/textmap.go index 845197e6f9..f26546dffb 100644 --- a/ddtrace/tracer/textmap.go +++ b/ddtrace/tracer/textmap.go @@ -514,18 +514,18 @@ func validateTID(tid string) error { } func getPropagatorType(p Propagator) string { - // switch p.(type) { - - if _, isW3c := p.(*propagatorW3c); isW3c { + switch p.(type) { + case *propagatorW3c: return "tracecontext" - } else if _, isDD := p.(*propagator); isDD { + case *propagator: return "datadog" - } else if _, isB3 := p.(*propagatorB3); isB3 { - return "b3" - } else if _, isB3SingleHeader := p.(*propagatorB3SingleHeader); isB3SingleHeader { - return "B3 single header" + case *propagatorB3: + return "b3multi" + case *propagatorB3SingleHeader: + return "b3 single header" + default: + return "" } - return "" } // getDatadogPropagator returns the Datadog Propagator diff --git a/ddtrace/tracer/textmap_test.go b/ddtrace/tracer/textmap_test.go index 50da266d96..670bf4facf 100644 --- a/ddtrace/tracer/textmap_test.go +++ b/ddtrace/tracer/textmap_test.go @@ -1980,7 +1980,7 @@ func TestInvalidTraceSpanLinkCreation(t *testing.T) { DefaultTraceIDHeader: "1", DefaultParentIDHeader: "1", DefaultPriorityHeader: "3", - traceparentHeader: "00-00000000000000000000000000000002-0000000000000002-01", + traceparentHeader: "00-00000000000000000000000000000001-0000000000000002-01", tracestateHeader: "dd=s:1;o:rum;t.usr.id:baz64~~", }, out: []ddtrace.SpanLink{{TraceID: 2, TraceIDHigh: 0, SpanID: 2, Tracestate: "dd=s:1;o:rum;t.usr.id:baz64~~", Flags: 1, Attributes: map[string]string{"reason": "terminated_context", "context_headers": "tracecontext"}}, {TraceID: 1, TraceIDHigh: 0, SpanID: 1, Flags: 1, Attributes: map[string]string{"reason": "terminated_context", "context_headers": "datadog"}}},