Debian Codegraph @

consumer/xconsumer/profiles.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package xconsumer // import "go.opentelemetry.io/collector/consumer/xconsumer"
5
6 import (
7 "context"
8 "errors"
9
10 "go.opentelemetry.io/collector/consumer"
11 "go.opentelemetry.io/collector/consumer/internal"
12 "go.opentelemetry.io/collector/pdata/pprofile"
13 )
14
15 var errNilFunc = errors.New("nil consumer func")
16
17 // Profiles is an interface that receives pprofile.Profiles, processes it
18 // as needed, and sends it to the next processing node if any or to the destination.
19 type Profiles interface {
20 internal.BaseConsumer
21 // ConsumeProfiles processes the profiles. After the function returns, the profiles are no longer accessible,
22 // and accessing them is considered undefined behavior.
23 ConsumeProfiles(ctx context.Context, td pprofile.Profiles) error
24 }
25
26 // ConsumeProfilesFunc is a helper function that is similar to ConsumeProfiles.
27 type ConsumeProfilesFunc func(ctx context.Context, td pprofile.Profiles) error
28
29 // ConsumeProfiles calls f(ctx, td).
30 func (f ConsumeProfilesFunc) ConsumeProfiles(ctx context.Context, td pprofile.Profiles) error {
31 return f(ctx, td)
32 }
33
34 type baseProfiles struct {
35 *internal.BaseImpl
36 ConsumeProfilesFunc
37 }
38
39 // NewProfiles returns a Profiles configured with the provided options.
40 func NewProfiles(consume ConsumeProfilesFunc, options ...consumer.Option) (Profiles, error) {
41 if consume == nil {
42 return nil, errNilFunc
43 }
44 return &baseProfiles{
45 BaseImpl: internal.NewBaseImpl(options...),
46 ConsumeProfilesFunc: consume,
47 }, nil
48 }