| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package refconsumer // import "go.opentelemetry.io/collector/service/internal/refconsumer" |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/consumer" |
| 10 |
"go.opentelemetry.io/collector/consumer/xconsumer" |
| 11 |
"go.opentelemetry.io/collector/pdata/pprofile" |
| 12 |
"go.opentelemetry.io/collector/pdata/xpdata/pref" |
| 13 |
) |
| 14 |
|
| 15 |
func NewProfiles(cons xconsumer.Profiles) xconsumer.Profiles { |
| 16 |
return refProfiles{ |
| 17 |
consumer: cons, |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
type refProfiles struct { |
| 22 |
consumer xconsumer.Profiles |
| 23 |
} |
| 24 |
|
| 25 |
// ConsumeProfiles measures telemetry before calling ConsumeProfiles because the data may be mutated downstream |
| 26 |
func (c refProfiles) ConsumeProfiles(ctx context.Context, ld pprofile.Profiles) error { |
| 27 |
if pref.MarkPipelineOwnedProfiles(ld) { |
| 28 |
defer pref.UnrefProfiles(ld) |
| 29 |
} |
| 30 |
return c.consumer.ConsumeProfiles(ctx, ld) |
| 31 |
} |
| 32 |
|
| 33 |
func (c refProfiles) Capabilities() consumer.Capabilities { |
| 34 |
return c.consumer.Capabilities() |
| 35 |
} |