Files
Bogdan DrutuandGitHub 0a2e66cc48 Implement refcounting for pipeline data owned memory (#13650)
This feature is protected by the beta featuregate
`pdata.enableRefCounting` so that if unexpected problems occur to have a
simple way to disable the problematic logic. If nothing goes wrong for 2
versions this featuregate will be marked as stable.

Updates
https://github.com/open-telemetry/opentelemetry-collector/issues/13631

Signed-off-by: Bogdan Drutu <[email protected]>
2025-08-22 17:12:05 +00:00

35 lines
849 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package refconsumer // import "go.opentelemetry.io/collector/service/internal/refconsumer"
import (
"context"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/xpdata/pref"
)
func NewLogs(cons consumer.Logs) consumer.Logs {
return refLogs{
consumer: cons,
}
}
type refLogs struct {
consumer consumer.Logs
}
// ConsumeLogs measures telemetry before calling ConsumeLogs because the data may be mutated downstream
func (c refLogs) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
if pref.MarkPipelineOwnedLogs(ld) {
defer pref.UnrefLogs(ld)
}
return c.consumer.ConsumeLogs(ctx, ld)
}
func (c refLogs) Capabilities() consumer.Capabilities {
return c.consumer.Capabilities()
}