Debian Codegraph @

consumer/metrics.go

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