Files
Florian LehnerandGitHub ea33e7d8d4 Fix pprofile DurationNano to be a TypeUint64 (#14188)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

pcommon.Timestamp better represents a point in time rather than a
duration. So keeping the proto field type for DurationNano is a better
fit.

Corresponding Collector-contrib change:
https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/44397

ping @open-telemetry/profiling-approvers 

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Signed-off-by: Florian Lehner <[email protected]>
2025-11-20 15:43:15 +00:00

68 lines
2.0 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package otlptext // import "go.opentelemetry.io/collector/exporter/debugexporter/internal/otlptext"
import (
"strconv"
"go.opentelemetry.io/collector/pdata/pprofile"
)
// NewTextProfilesMarshaler returns a pprofile.Marshaler to encode to OTLP text bytes.
func NewTextProfilesMarshaler() pprofile.Marshaler {
return textProfilesMarshaler{}
}
type textProfilesMarshaler struct{}
// MarshalProfiles pprofile.Profiles to OTLP text.
func (textProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, error) {
buf := dataBuffer{}
dic := pd.Dictionary()
rps := pd.ResourceProfiles()
buf.logProfileMappings(dic.MappingTable())
buf.logProfileLocations(dic.LocationTable())
buf.logProfileFunctions(dic.FunctionTable())
buf.logAttributesWithIndentation(
"Attribute table",
keyValueAndUnitsToMap(dic.AttributeTable()),
0)
buf.logAttributesWithIndentation(
"Link table",
linkTableToMap(dic.LinkTable()),
0)
buf.logStringTable(dic.StringTable())
for i := 0; i < rps.Len(); i++ {
buf.logEntry("ResourceProfiles #%d", i)
rp := rps.At(i)
buf.logEntry("Resource SchemaURL: %s", rp.SchemaUrl())
buf.logAttributes("Resource attributes", rp.Resource().Attributes())
buf.logEntityRefs(rp.Resource())
ilps := rp.ScopeProfiles()
for j := 0; j < ilps.Len(); j++ {
buf.logEntry("ScopeProfiles #%d", j)
ilp := ilps.At(j)
buf.logEntry("ScopeProfiles SchemaURL: %s", ilp.SchemaUrl())
buf.logInstrumentationScope(ilp.Scope())
profiles := ilp.Profiles()
for k := 0; k < profiles.Len(); k++ {
buf.logEntry("Profile #%d", k)
profile := profiles.At(k)
buf.logAttr("Profile ID", profile.ProfileID())
buf.logAttr("Start time", profile.Time().String())
buf.logAttr("DurationNano", strconv.FormatUint(profile.DurationNano(), 10))
buf.logAttr("Dropped attributes count", strconv.FormatUint(uint64(profile.DroppedAttributesCount()), 10))
buf.logProfileSamples(profile.Samples(), dic)
}
}
}
return buf.buf.Bytes(), nil
}