| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package consumertest // import "go.opentelemetry.io/collector/consumer/consumertest" |
| 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/plog" |
| 12 |
"go.opentelemetry.io/collector/pdata/pmetric" |
| 13 |
"go.opentelemetry.io/collector/pdata/pprofile" |
| 14 |
"go.opentelemetry.io/collector/pdata/ptrace" |
| 15 |
) |
| 16 |
|
| 17 |
// Consumer is a convenience interface that implements all consumer interfaces. |
| 18 |
// It has a private function on it to forbid external users from implementing it |
| 19 |
// and, as a result, to allow us to add extra functions without breaking |
| 20 |
// compatibility. |
| 21 |
type Consumer interface { |
| 22 |
// Capabilities to implement the base consumer functionality. |
| 23 |
Capabilities() consumer.Capabilities |
| 24 |
|
| 25 |
// ConsumeTraces to implement the consumer.Traces. |
| 26 |
ConsumeTraces(context.Context, ptrace.Traces) error |
| 27 |
|
| 28 |
// ConsumeMetrics to implement the consumer.Metrics. |
| 29 |
ConsumeMetrics(context.Context, pmetric.Metrics) error |
| 30 |
|
| 31 |
// ConsumeLogs to implement the consumer.Logs. |
| 32 |
ConsumeLogs(context.Context, plog.Logs) error |
| 33 |
|
| 34 |
// ConsumeProfiles to implement the xconsumer.Profiles. |
| 35 |
ConsumeProfiles(context.Context, pprofile.Profiles) error |
| 36 |
|
| 37 |
unexported() |
| 38 |
} |
| 39 |
|
| 40 |
var ( |
| 41 |
_ consumer.Logs = Consumer(nil) |
| 42 |
_ consumer.Metrics = Consumer(nil) |
| 43 |
_ consumer.Traces = Consumer(nil) |
| 44 |
_ xconsumer.Profiles = Consumer(nil) |
| 45 |
) |
| 46 |
|
| 47 |
type nonMutatingConsumer struct{} |
| 48 |
|
| 49 |
// Capabilities returns the base consumer capabilities. |
| 50 |
func (bc nonMutatingConsumer) Capabilities() consumer.Capabilities { |
| 51 |
return consumer.Capabilities{MutatesData: false} |
| 52 |
} |
| 53 |
|
| 54 |
type baseConsumer struct { |
| 55 |
nonMutatingConsumer |
| 56 |
consumer.ConsumeTracesFunc |
| 57 |
consumer.ConsumeMetricsFunc |
| 58 |
consumer.ConsumeLogsFunc |
| 59 |
xconsumer.ConsumeProfilesFunc |
| 60 |
} |
| 61 |
|
| 62 |
func (bc baseConsumer) unexported() {} |