diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index 51769cd8..ecc558ab 100644 --- a/reporter/otlp_reporter.go +++ b/reporter/otlp_reporter.go @@ -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 { @@ -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}, @@ -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) @@ -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]{ @@ -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]{