Skip to content

Commit

Permalink
[pkg/stanza] panic when converting empty trace_flags []byte (#21031)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgranetzke authored Apr 18, 2023
1 parent 437382c commit 98d0afb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .chloggen/stanza_converter_panic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: filelogreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: stanza panic when trace_flags is an empty string

# One or more tracking issues related to the change
issues: [20924]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 1 addition & 1 deletion pkg/stanza/adapter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func convertInto(ent *entry.Entry, dest plog.LogRecord) {
copy(buffer[0:8], ent.SpanID)
dest.SetSpanID(buffer)
}
if ent.TraceFlags != nil {
if ent.TraceFlags != nil && len(ent.TraceFlags) > 0 {
// The 8 least significant bits are the trace flags as defined in W3C Trace
// Context specification. Don't override the 24 reserved bits.
flags := uint32(ent.TraceFlags[0])
Expand Down
21 changes: 21 additions & 0 deletions pkg/stanza/adapter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,27 @@ func TestConvertTrace(t *testing.T) {
require.Equal(t, uint32(0x01), uint32(record.Flags()))
}

func TestConvertTraceEmptyFlags(t *testing.T) {
record := convertAndDrill(&entry.Entry{
TraceID: []byte{
0x48, 0x01, 0x40, 0xf3, 0xd7, 0x70, 0xa5, 0xae, 0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff,
},
SpanID: []byte{
0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff,
},
TraceFlags: []byte{}})

require.Equal(t, pcommon.TraceID(
[16]byte{
0x48, 0x01, 0x40, 0xf3, 0xd7, 0x70, 0xa5, 0xae, 0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff,
}), record.TraceID())
require.Equal(t, pcommon.SpanID(
[8]byte{
0x32, 0xf0, 0xa2, 0x2b, 0x6a, 0x81, 0x2c, 0xff,
}), record.SpanID())
require.Equal(t, uint32(0x00), uint32(record.Flags()))
}

func BenchmarkConverter(b *testing.B) {
const (
entryCount = 1_000_000
Expand Down

0 comments on commit 98d0afb

Please sign in to comment.