mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
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]>
25 lines
732 B
Go
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
|
|
}
|