Skip to content

Commit

Permalink
Fix crash in sapmexporter, when iterate with range changes to len are…
Browse files Browse the repository at this point in the history
… not visible

Fixes open-telemetry#3279

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Apr 30, 2021
1 parent d391732 commit 2914d28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 6 additions & 7 deletions exporter/sapmexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ func filterTokenFromProcess(proc *model.Process) {
if proc == nil {
return
}
for i := range proc.Tags {
for i := 0; i < len(proc.Tags); {
if proc.Tags[i].Key == splunk.SFxAccessTokenLabel {
// Switch this tag with last one.
lastPos := len(proc.Tags) - 1
tmp := proc.Tags[lastPos]
proc.Tags[lastPos] = proc.Tags[i]
proc.Tags[i] = tmp
proc.Tags = proc.Tags[0:lastPos]
proc.Tags[i] = proc.Tags[len(proc.Tags)-1]
// We do not need to put proc.Tags[i] at the end, as it will be discarded anyway
proc.Tags = proc.Tags[:len(proc.Tags)-1]
continue
}
i++
}
}
6 changes: 6 additions & 0 deletions exporter/sapmexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ func buildTestTraces(setTokenLabel bool) (traces pdata.Traces) {
for i := 0; i < 20; i++ {
rs := rss.At(i)
resource := rs.Resource()
resource.Attributes().InsertString("key1", "value1")
if setTokenLabel && i%2 == 1 {
tokenLabel := fmt.Sprintf("MyToken%d", i/5)
resource.Attributes().InsertString("com.splunk.signalfx.access_token", tokenLabel)
resource.Attributes().InsertString("com.splunk.signalfx.access_token", tokenLabel)
}
// Add one last element every 3rd resource, this way we have cases with token last or not.
if i%3 == 1 {
resource.Attributes().InsertString("key2", "value2")
}

span := rs.InstrumentationLibrarySpans().AppendEmpty().Spans().AppendEmpty()
Expand Down

0 comments on commit 2914d28

Please sign in to comment.