Skip to content

Commit

Permalink
Add FromRaw to Flags struct
Browse files Browse the repository at this point in the history
See usages in open-telemetry/opentelemetry-collector-contrib#13617 where we had to check for the sample bit to set the value instead of just setting the entire value.

Signed-off-by: Bogdan <[email protected]>
  • Loading branch information
bogdandrutu committed Aug 25, 2022
1 parent 58fa059 commit f785386
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pdata/plog/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ func (ms LogRecordFlags) SetIsSampled(b bool) {
}
}

// FromRaw converts from the OTLP uint32 representation into this LogRecordFlags.
func (ms LogRecordFlags) FromRaw(val uint32) {
*ms.getOrig() = val
}

// AsRaw converts LogRecordFlags to the OTLP uint32 representation.
func (ms LogRecordFlags) AsRaw() uint32 {
return *ms.getOrig()
Expand Down
4 changes: 4 additions & 0 deletions pdata/plog/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func TestLogRecordFlags(t *testing.T) {
moveFlags.CopyTo(flags)
assert.True(t, flags.IsSampled())
assert.True(t, moveFlags.IsSampled())

flags.FromRaw(127)
assert.True(t, flags.IsSampled())
assert.Equal(t, uint32(127), flags.AsRaw())
}

func BenchmarkLogsClone(b *testing.B) {
Expand Down
5 changes: 5 additions & 0 deletions pdata/pmetric/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ func (ms MetricDataPointFlags) SetNoRecordedValue(b bool) {
}
}

// FromRaw converts from the OTLP uint32 representation into this LogRecordFlags.
func (ms MetricDataPointFlags) FromRaw(val uint32) {
*ms.getOrig() = val
}

// AsRaw converts MetricDataPointFlags to the OTLP uint32 representation.
func (ms MetricDataPointFlags) AsRaw() uint32 {
return *ms.getOrig()
Expand Down
4 changes: 4 additions & 0 deletions pdata/pmetric/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ func TestMetricDataPointFlags(t *testing.T) {
moveFlags.CopyTo(flags)
assert.True(t, flags.NoRecordedValue())
assert.True(t, moveFlags.NoRecordedValue())

flags.FromRaw(127)
assert.True(t, flags.NoRecordedValue())
assert.Equal(t, uint32(127), flags.AsRaw())
}

func BenchmarkMetricsClone(b *testing.B) {
Expand Down

0 comments on commit f785386

Please sign in to comment.