mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
This is a huge PR that does not touch any of the critical logic "marshaling/unmarshaling" of the pdata. We have e2e tests with the go official generated protobufs to ensure nothing breaks. The easy way to review this is to only look at what change publicly in "pdata/pcommon", "pdata/plog", "pdata/ptrace", "pdata/pmetric", "pdata/pprofile", "pdata/xpdata". This PR also switches the xpada request to use the same generating mechanism as pdatagen. **Binary size before:** ``` 42246018 bin/otelcorecol_darwin_arm64 ``` **Binary size after:** ``` 40709202 bin/otelcorecol_darwin_arm64 ``` Signed-off-by: Bogdan Drutu <[email protected]>
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package request // import "go.opentelemetry.io/collector/pdata/xpdata/request"
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"go.opentelemetry.io/collector/pdata/internal"
|
|
"go.opentelemetry.io/collector/pdata/pprofile"
|
|
)
|
|
|
|
// MarshalProfiles marshals pprofile.Profiles along with the context into a byte slice.
|
|
func MarshalProfiles(ctx context.Context, ld pprofile.Profiles) ([]byte, error) {
|
|
pr := internal.ProfilesRequest{
|
|
FormatVersion: requestFormatVersion,
|
|
ProfilesData: internal.ProfilesToProto(internal.ProfilesWrapper(ld)),
|
|
RequestContext: encodeContext(ctx),
|
|
}
|
|
buf := make([]byte, pr.SizeProto())
|
|
pr.MarshalProto(buf)
|
|
return buf, nil
|
|
}
|
|
|
|
// UnmarshalProfiles unmarshals a byte slice into pprofile.Profiles and the context.
|
|
func UnmarshalProfiles(buf []byte) (context.Context, pprofile.Profiles, error) {
|
|
ctx := context.Background()
|
|
if !isRequestPayloadV1(buf) {
|
|
return ctx, pprofile.Profiles{}, ErrInvalidFormat
|
|
}
|
|
pr := internal.ProfilesRequest{}
|
|
if err := pr.UnmarshalProto(buf); err != nil {
|
|
return ctx, pprofile.Profiles{}, fmt.Errorf("failed to unmarshal profiles request: %w", err)
|
|
}
|
|
return decodeContext(ctx, pr.RequestContext), pprofile.Profiles(internal.ProfilesFromProto(pr.ProfilesData)), nil
|
|
}
|