From 5990215445d10a815eeb9f435db04147881f1135 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 7 Oct 2022 17:23:50 -0700 Subject: [PATCH] [pdata] Rename ptrace.SpanStatus to trace.Status --- CHANGELOG.md | 1 + .../cmd/pdatagen/internal/trace_structs.go | 4 +- pdata/internal/generated_wrapper_traces.go | 18 ++++---- pdata/ptrace/generated_traces.go | 44 +++++++++---------- pdata/ptrace/generated_traces_test.go | 30 ++++++------- pdata/ptrace/traces.go | 6 +++ 6 files changed, 55 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d967c9ccae..a209aecad60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - Deprecate `pcommon.NewValueString` in favor of `pcommon.NewValueStr` (#6209) - Deprecate `pmetric.MetricAggregationTemporality` enum type in favor of `pmetric.AggregationTemporality` (#6249) - Deprecate `confmap.Conf.UnmarshalExact` in favor of `confmap.Conf.Unmarshal(.., WithErrorUnused)` (#6231) +- Deprecate `ptrace.SpanStatus` favor of `ptrace.Status` (#6258) ### 💡 Enhancements 💡 diff --git a/pdata/internal/cmd/pdatagen/internal/trace_structs.go b/pdata/internal/cmd/pdatagen/internal/trace_structs.go index b310883025c..e0310299b10 100644 --- a/pdata/internal/cmd/pdatagen/internal/trace_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/trace_structs.go @@ -188,8 +188,8 @@ var spanLink = &messageValueStruct{ } var spanStatus = &messageValueStruct{ - structName: "SpanStatus", - description: "// SpanStatus is an optional final status for this span. Semantically, when Status was not\n" + + structName: "Status", + description: "// Status is an optional final status for this span. Semantically, when Status was not\n" + "// set, that means the span ended without errors and to assume Status.Ok (code = 0).", originFullName: "otlptrace.Status", fields: []baseField{ diff --git a/pdata/internal/generated_wrapper_traces.go b/pdata/internal/generated_wrapper_traces.go index 1dee186ef3e..38d7e69d117 100644 --- a/pdata/internal/generated_wrapper_traces.go +++ b/pdata/internal/generated_wrapper_traces.go @@ -142,16 +142,16 @@ func NewSpanLink(orig *otlptrace.Span_Link) SpanLink { return SpanLink{orig: orig} } -type SpanStatus struct { +type Status struct { orig *otlptrace.Status } -func GetOrigSpanStatus(ms SpanStatus) *otlptrace.Status { +func GetOrigStatus(ms Status) *otlptrace.Status { return ms.orig } -func NewSpanStatus(orig *otlptrace.Status) SpanStatus { - return SpanStatus{orig: orig} +func NewStatus(orig *otlptrace.Status) Status { + return Status{orig: orig} } func GenerateTestResourceSpansSlice() ResourceSpansSlice { @@ -247,7 +247,7 @@ func FillTestSpan(tv Span) { tv.orig.DroppedEventsCount = uint32(17) FillTestSpanLinkSlice(NewSpanLinkSlice(&tv.orig.Links)) tv.orig.DroppedLinksCount = uint32(17) - FillTestSpanStatus(NewSpanStatus(&tv.orig.Status)) + FillTestStatus(NewStatus(&tv.orig.Status)) } func GenerateTestSpanEventSlice() SpanEventSlice { @@ -309,14 +309,14 @@ func FillTestSpanLink(tv SpanLink) { tv.orig.DroppedAttributesCount = uint32(17) } -func GenerateTestSpanStatus() SpanStatus { +func GenerateTestStatus() Status { orig := otlptrace.Status{} - tv := NewSpanStatus(&orig) - FillTestSpanStatus(tv) + tv := NewStatus(&orig) + FillTestStatus(tv) return tv } -func FillTestSpanStatus(tv SpanStatus) { +func FillTestStatus(tv Status) { tv.orig.Code = 1 tv.orig.Message = "cancelled" } diff --git a/pdata/ptrace/generated_traces.go b/pdata/ptrace/generated_traces.go index e6ee7a0d900..3b5ac63b9b6 100644 --- a/pdata/ptrace/generated_traces.go +++ b/pdata/ptrace/generated_traces.go @@ -721,8 +721,8 @@ func (ms Span) SetDroppedLinksCount(v uint32) { } // Status returns the status associated with this Span. -func (ms Span) Status() SpanStatus { - return SpanStatus(internal.NewSpanStatus(&ms.getOrig().Status)) +func (ms Span) Status() Status { + return Status(internal.NewStatus(&ms.getOrig().Status)) } // CopyTo copies all properties from the current struct to the dest. @@ -1185,62 +1185,62 @@ func (ms SpanLink) CopyTo(dest SpanLink) { dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) } -// SpanStatus is an optional final status for this span. Semantically, when Status was not +// Status is an optional final status for this span. Semantically, when Status was not // set, that means the span ended without errors and to assume Status.Ok (code = 0). // // This is a reference type, if passed by value and callee modifies it the // caller will see the modification. // -// Must use NewSpanStatus function to create new instances. +// Must use NewStatus function to create new instances. // Important: zero-initialized instance is not valid for use. -type SpanStatus internal.SpanStatus +type Status internal.Status -func newSpanStatus(orig *otlptrace.Status) SpanStatus { - return SpanStatus(internal.NewSpanStatus(orig)) +func newStatus(orig *otlptrace.Status) Status { + return Status(internal.NewStatus(orig)) } -func (ms SpanStatus) getOrig() *otlptrace.Status { - return internal.GetOrigSpanStatus(internal.SpanStatus(ms)) +func (ms Status) getOrig() *otlptrace.Status { + return internal.GetOrigStatus(internal.Status(ms)) } -// NewSpanStatus creates a new empty SpanStatus. +// NewStatus creates a new empty Status. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSpanStatus() SpanStatus { - return newSpanStatus(&otlptrace.Status{}) +func NewStatus() Status { + return newStatus(&otlptrace.Status{}) } // MoveTo moves all properties from the current struct to dest // resetting the current instance to its zero value -func (ms SpanStatus) MoveTo(dest SpanStatus) { +func (ms Status) MoveTo(dest Status) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlptrace.Status{} } -// Code returns the code associated with this SpanStatus. -func (ms SpanStatus) Code() StatusCode { +// Code returns the code associated with this Status. +func (ms Status) Code() StatusCode { return StatusCode(ms.getOrig().Code) } -// SetCode replaces the code associated with this SpanStatus. -func (ms SpanStatus) SetCode(v StatusCode) { +// SetCode replaces the code associated with this Status. +func (ms Status) SetCode(v StatusCode) { ms.getOrig().Code = otlptrace.Status_StatusCode(v) } -// Message returns the message associated with this SpanStatus. -func (ms SpanStatus) Message() string { +// Message returns the message associated with this Status. +func (ms Status) Message() string { return ms.getOrig().Message } -// SetMessage replaces the message associated with this SpanStatus. -func (ms SpanStatus) SetMessage(v string) { +// SetMessage replaces the message associated with this Status. +func (ms Status) SetMessage(v string) { ms.getOrig().Message = v } // CopyTo copies all properties from the current struct to the dest. -func (ms SpanStatus) CopyTo(dest SpanStatus) { +func (ms Status) CopyTo(dest Status) { dest.SetCode(ms.Code()) dest.SetMessage(ms.Message()) } diff --git a/pdata/ptrace/generated_traces_test.go b/pdata/ptrace/generated_traces_test.go index 03e89238785..51abb471ebe 100644 --- a/pdata/ptrace/generated_traces_test.go +++ b/pdata/ptrace/generated_traces_test.go @@ -557,8 +557,8 @@ func TestSpan_DroppedLinksCount(t *testing.T) { func TestSpan_Status(t *testing.T) { ms := NewSpan() - internal.FillTestSpanStatus(internal.SpanStatus(ms.Status())) - assert.Equal(t, SpanStatus(internal.GenerateTestSpanStatus()), ms.Status()) + internal.FillTestStatus(internal.Status(ms.Status())) + assert.Equal(t, Status(internal.GenerateTestStatus()), ms.Status()) } func TestSpanEventSlice(t *testing.T) { @@ -882,34 +882,34 @@ func TestSpanLink_DroppedAttributesCount(t *testing.T) { assert.Equal(t, uint32(17), ms.DroppedAttributesCount()) } -func TestSpanStatus_MoveTo(t *testing.T) { - ms := SpanStatus(internal.GenerateTestSpanStatus()) - dest := NewSpanStatus() +func TestStatus_MoveTo(t *testing.T) { + ms := Status(internal.GenerateTestStatus()) + dest := NewStatus() ms.MoveTo(dest) - assert.Equal(t, NewSpanStatus(), ms) - assert.Equal(t, SpanStatus(internal.GenerateTestSpanStatus()), dest) + assert.Equal(t, NewStatus(), ms) + assert.Equal(t, Status(internal.GenerateTestStatus()), dest) } -func TestSpanStatus_CopyTo(t *testing.T) { - ms := NewSpanStatus() - orig := NewSpanStatus() +func TestStatus_CopyTo(t *testing.T) { + ms := NewStatus() + orig := NewStatus() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SpanStatus(internal.GenerateTestSpanStatus()) + orig = Status(internal.GenerateTestStatus()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } -func TestSpanStatus_Code(t *testing.T) { - ms := NewSpanStatus() +func TestStatus_Code(t *testing.T) { + ms := NewStatus() assert.Equal(t, StatusCode(0), ms.Code()) testValCode := StatusCode(1) ms.SetCode(testValCode) assert.Equal(t, testValCode, ms.Code()) } -func TestSpanStatus_Message(t *testing.T) { - ms := NewSpanStatus() +func TestStatus_Message(t *testing.T) { + ms := NewStatus() assert.Equal(t, "", ms.Message()) ms.SetMessage("cancelled") assert.Equal(t, "cancelled", ms.Message()) diff --git a/pdata/ptrace/traces.go b/pdata/ptrace/traces.go index a50ea7ea306..9b4bcbcaf41 100644 --- a/pdata/ptrace/traces.go +++ b/pdata/ptrace/traces.go @@ -110,3 +110,9 @@ const ( // String returns the string representation of the StatusCode. func (sc StatusCode) String() string { return otlptrace.Status_StatusCode(sc).String() } + +// Deprecated: [0.62.0] Use Status instead. +type SpanStatus = Status + +// Deprecated: [0.62.0] Use NewStatus instead. +var NewSpanStatus = NewStatus