| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package internal // import "go.opentelemetry.io/collector/consumer/internal" |
| 5 |
|
| 6 |
// Capabilities describes the capabilities of a Processor. |
| 7 |
type Capabilities struct { |
| 8 |
// MutatesData is set to true if Consume* function of the |
| 9 |
// processor modifies the input Traces, Logs or Metrics argument. |
| 10 |
// Processors which modify the input data MUST set this flag to true. If the processor |
| 11 |
// does not modify the data it MUST set this flag to false. If the processor creates |
| 12 |
// a copy of the data before modifying then this flag can be safely set to false. |
| 13 |
MutatesData bool |
| 14 |
} |
| 15 |
|
| 16 |
type BaseConsumer interface { |
| 17 |
Capabilities() Capabilities |
| 18 |
} |
| 19 |
|
| 20 |
type BaseImpl struct { |
| 21 |
Cap Capabilities |
| 22 |
} |
| 23 |
|
| 24 |
// Option to construct new consumers. |
| 25 |
type Option interface { |
| 26 |
apply(*BaseImpl) |
| 27 |
} |
| 28 |
|
| 29 |
type OptionFunc func(*BaseImpl) |
| 30 |
|
| 31 |
func (of OptionFunc) apply(e *BaseImpl) { |
| 32 |
of(e) |
| 33 |
} |
| 34 |
|
| 35 |
// Capabilities returns the capabilities of the component |
| 36 |
func (bs BaseImpl) Capabilities() Capabilities { |
| 37 |
return bs.Cap |
| 38 |
} |
| 39 |
|
| 40 |
func NewBaseImpl(options ...Option) *BaseImpl { |
| 41 |
bs := &BaseImpl{ |
| 42 |
Cap: Capabilities{MutatesData: false}, |
| 43 |
} |
| 44 |
|
| 45 |
for _, op := range options { |
| 46 |
op.apply(bs) |
| 47 |
} |
| 48 |
|
| 49 |
return bs |
| 50 |
} |