mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
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]>
35 lines
900 B
Go
35 lines
900 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/pmetric"
|
|
"go.opentelemetry.io/collector/pdata/xpdata/pref"
|
|
)
|
|
|
|
func NewMetrics(cons consumer.Metrics) consumer.Metrics {
|
|
return refMetrics{
|
|
consumer: cons,
|
|
}
|
|
}
|
|
|
|
type refMetrics struct {
|
|
consumer consumer.Metrics
|
|
}
|
|
|
|
// ConsumeMetrics measures telemetry before calling ConsumeMetrics because the data may be mutated downstream
|
|
func (c refMetrics) ConsumeMetrics(ctx context.Context, ld pmetric.Metrics) error {
|
|
if pref.MarkPipelineOwnedMetrics(ld) {
|
|
defer pref.UnrefMetrics(ld)
|
|
}
|
|
return c.consumer.ConsumeMetrics(ctx, ld)
|
|
}
|
|
|
|
func (c refMetrics) Capabilities() consumer.Capabilities {
|
|
return c.consumer.Capabilities()
|
|
}
|