Skip to content

Commit

Permalink
fixup: fix indexing issue
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl committed Dec 1, 2024
1 parent 3a7f23c commit 90a134e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (r *OTLPReporter) getResource() *resource.Resource {
// getProfile returns an OTLP profile containing all collected traces up to this moment.
func (r *OTLPReporter) getProfile(origin int) (profile *profiles.Profile, startTS, endTS uint64) {
samples := r.getEventsFromOrigin(origin)
stringMap, funcMap, attributeMap := getHelperMaps()
stringMap, funcMap, attributeMap, fileIDtoMapping := getHelperMaps()

numSamples := len(samples)
switch origin {
Expand Down Expand Up @@ -574,7 +574,7 @@ func (r *OTLPReporter) getProfile(origin int) (profile *profiles.Profile, startT
}
}

r.populateTrace(profile, traceInfo, stringMap, funcMap, attributeMap)
r.populateTrace(profile, traceInfo, stringMap, funcMap, attributeMap, fileIDtoMapping)

sample.Attributes = append(addProfileAttributes(profile, []attrKeyValue[string]{
{key: string(semconv.ContainerIDKey), value: traceKey.containerID},
Expand Down Expand Up @@ -609,7 +609,7 @@ func (r *OTLPReporter) getEventsFromOrigin(kind int) samplesMap {

// getHelperMaps returns temporary maps that support constructing a profile.
func getHelperMaps() (stringMap map[string]uint32, funcMap map[funcInfo]uint64,
attributeMap map[string]uint64) {
attributeMap map[string]uint64, fileIDtoMapping map[libpf.FileID]uint64) {
// stringMap is a temporary helper that will build the StringTable.
// By specification, the first element should be empty.
stringMap = make(map[string]uint32)
Expand All @@ -625,14 +625,15 @@ func getHelperMaps() (stringMap map[string]uint32, funcMap map[funcInfo]uint64,
// This is to ensure that AttributeTable does not contain duplicates.
attributeMap = make(map[string]uint64)

return stringMap, funcMap, attributeMap
// Temporary lookup to reference existing Mappings.
fileIDtoMapping = make(map[libpf.FileID]uint64)

return stringMap, funcMap, attributeMap, fileIDtoMapping
}

func (r *OTLPReporter) populateTrace(profile *profiles.Profile, traceInfo *traceEvents,
stringMap map[string]uint32, funcMap map[funcInfo]uint64, attributeMap map[string]uint64) {
// Temporary lookup to reference existing Mappings.
fileIDtoMapping := make(map[libpf.FileID]uint64)

stringMap map[string]uint32, funcMap map[funcInfo]uint64,
attributeMap map[string]uint64, fileIDtoMapping map[libpf.FileID]uint64) {
// Walk every frame of the trace.
for i := range traceInfo.frameTypes {
frameAttributes := addProfileAttributes(profile, []attrKeyValue[string]{
Expand Down Expand Up @@ -846,7 +847,7 @@ func getDummyMappingIndex(fileIDtoMapping map[libpf.FileID]uint64,
if tmpMappingIndex, exists := fileIDtoMapping[fileID]; exists {
return tmpMappingIndex
}
idx := uint64(len(fileIDtoMapping))
idx := uint64(len(profile.Mapping))
fileIDtoMapping[fileID] = idx

mappingAttributes := addProfileAttributes(profile, []attrKeyValue[string]{
Expand Down

0 comments on commit 90a134e

Please sign in to comment.