Skip to content

Commit

Permalink
Enforce naming conventions for Invalid[Trace|Span]ID (#5969)
Browse files Browse the repository at this point in the history
* Enforce naming conventions for Invalid[Trace|Span]ID

See the rules here https://github.com/open-telemetry/opentelemetry-collector/blob/main/CONTRIBUTING.md#naming-convention

Also this changes Invalid -> Empty to match the "IsEmpty" func.

Signed-off-by: Bogdan <bogdandrutu@gmail.com>

* Update traceid.go

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Aug 25, 2022
1 parent 7545a29 commit 40cd9ba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
- `MetricDataPointFlagsStruct` -> `MetricDataPointFlags`
- `NewMetricDataPointFlagsStruct` -> `NewMetricDataPointFlags`
- Deprecate builder distribution flags, use configuration. (#5946)
- Enforce naming conventions for Invalid[Trace|Span]ID: (#5969)
- Deprecate funcs `pcommon.InvalidTraceID` and `pcommon.InvalidSpanID` in favor of vars `pcommon.EmptyTraceID` and `pcommon.EmptySpanID`

### 💡 Enhancements 💡

Expand Down
7 changes: 5 additions & 2 deletions pdata/pcommon/spanid.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ import (
"go.opentelemetry.io/collector/pdata/internal/data"
)

// EmptySpanID represents the empty (all zero bytes) SpanID.
var EmptySpanID = NewSpanID([8]byte{})

// SpanID is span identifier.
type SpanID internal.SpanID

func (ms SpanID) getOrig() data.SpanID {
return internal.GetOrigSpanID(internal.SpanID(ms))
}

// InvalidSpanID returns an empty (all zero bytes) SpanID.
// Deprecated: [v0.59.0] use EmptySpanID.
func InvalidSpanID() SpanID {
return NewSpanID([8]byte{})
return EmptySpanID
}

// NewSpanID returns a new SpanID from the given byte array.
Expand Down
2 changes: 1 addition & 1 deletion pdata/pcommon/spanid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestSpanID(t *testing.T) {
sid := InvalidSpanID()
sid := EmptySpanID
assert.EqualValues(t, [8]byte{}, sid.Bytes())
assert.True(t, sid.IsEmpty())
assert.Equal(t, "", sid.HexString())
Expand Down
7 changes: 5 additions & 2 deletions pdata/pcommon/traceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ import (
"go.opentelemetry.io/collector/pdata/internal/data"
)

// EmptyTraceID represents the empty (all zero bytes) TraceID.
var EmptyTraceID = NewTraceID([16]byte{})

// TraceID is a trace identifier.
type TraceID internal.TraceID

func (ms TraceID) getOrig() data.TraceID {
return internal.GetOrigTraceID(internal.TraceID(ms))
}

// InvalidTraceID returns an empty (all zero bytes) TraceID.
// Deprecated: [v0.59.0] use EmptyTraceID.
func InvalidTraceID() TraceID {
return NewTraceID([16]byte{})
return EmptyTraceID
}

// NewTraceID returns a new TraceID from the given byte array.
Expand Down
2 changes: 1 addition & 1 deletion pdata/pcommon/traceid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestTraceID(t *testing.T) {
tid := InvalidTraceID()
tid := EmptyTraceID
assert.Equal(t, [16]byte{}, tid.Bytes())
assert.True(t, tid.IsEmpty())
assert.Equal(t, "", tid.HexString())
Expand Down

0 comments on commit 40cd9ba

Please sign in to comment.