Files
Israel BlancasandGitHub 09ec383943 Introduce MergeTo method for profiles (#14091)
Continuation
https://github.com/open-telemetry/opentelemetry-collector/issues/13106

* Added `Profiles.MergeTo` implementation that merges one profile
message into another while reconciling their dictionaries and appending
resource profiles.
* Added comprehensive unit tests covering both the successful merge path
and error propagation when dictionary switching fails.

---------

Signed-off-by: Israel Blancas <[email protected]>
2025-11-28 12:04:10 +00:00

25 lines
732 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
// MergeTo merges the current Profiles into dest, updating the destination
// dictionary as needed and appending the resource profiles.
// The source Profiles is consumed and marked read-only after this operation.
func (ms Profiles) MergeTo(dest Profiles) error {
ms.getState().AssertMutable()
dest.getState().AssertMutable()
if ms.getOrig() == dest.getOrig() {
return nil
}
if err := ms.switchDictionary(ms.Dictionary(), dest.Dictionary()); err != nil {
return err
}
ms.ResourceProfiles().MoveAndAppendTo(dest.ResourceProfiles())
ms.MarkReadOnly()
return nil
}