Documentation
¶
Overview ¶
Package consumer contains interfaces that receive and process data.
Example ¶
package main
import (
"context"
"fmt"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
// Create a Logs consumer using a ConsumeLogsFunc.
// By default, a consumer reports that it does not mutate data.
logs, err := consumer.NewLogs(func(_ context.Context, ld plog.Logs) error {
fmt.Printf("received %d log record(s)\n", ld.LogRecordCount())
return nil
})
if err != nil {
panic(err)
}
fmt.Printf("mutates data: %v\n", logs.Capabilities().MutatesData)
// Send some log data through the consumer.
ld := plog.NewLogs()
ld.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()
if err := logs.ConsumeLogs(context.Background(), ld); err != nil {
panic(err)
}
}
Output: mutates data: false received 1 log record(s)
Example (WithCapabilities) ¶
package main
import (
"context"
"fmt"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
// Create a Logs consumer that declares it mutates the data it receives.
// Processors that modify data in place should set MutatesData to true so
// that the pipeline knows to copy data before passing it to other consumers.
logs, err := consumer.NewLogs(
func(_ context.Context, ld plog.Logs) error {
fmt.Printf("processed %d log record(s)\n", ld.LogRecordCount())
return nil
},
consumer.WithCapabilities(consumer.Capabilities{MutatesData: true}),
)
if err != nil {
panic(err)
}
fmt.Printf("mutates data: %v\n", logs.Capabilities().MutatesData)
}
Output: mutates data: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capabilities ¶
type Capabilities = internal.Capabilities
Capabilities describes the capabilities of a Processor.
type ConsumeLogsFunc ¶
ConsumeLogsFunc is a helper function that is similar to ConsumeLogs.
func (ConsumeLogsFunc) ConsumeLogs ¶
ConsumeLogs calls f(ctx, ld).
type ConsumeMetricsFunc ¶
ConsumeMetricsFunc is a helper function that is similar to ConsumeMetrics.
func (ConsumeMetricsFunc) ConsumeMetrics ¶
ConsumeMetrics calls f(ctx, md).
type ConsumeTracesFunc ¶
ConsumeTracesFunc is a helper function that is similar to ConsumeTraces.
func (ConsumeTracesFunc) ConsumeTraces ¶
ConsumeTraces calls f(ctx, td).
type Logs ¶
type Logs interface {
internal.BaseConsumer
// ConsumeLogs processes the logs. After the function returns, the logs are no longer accessible,
// and accessing them is considered undefined behavior.
ConsumeLogs(ctx context.Context, ld plog.Logs) error
}
Logs is an interface that receives plog.Logs, processes it as needed, and sends it to the next processing node if any or to the destination.
type Metrics ¶
type Metrics interface {
internal.BaseConsumer
// ConsumeMetrics processes the metrics. After the function returns, the metrics are no longer accessible,
// and accessing them is considered undefined behavior.
ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error
}
Metrics is an interface that receives pmetric.Metrics, processes it as needed, and sends it to the next processing node if any or to the destination.
func NewMetrics ¶
func NewMetrics(consume ConsumeMetricsFunc, options ...Option) (Metrics, error)
NewMetrics returns a Metrics configured with the provided options.
type Option ¶
Option to construct new consumers.
func WithCapabilities ¶
func WithCapabilities(capabilities Capabilities) Option
WithCapabilities overrides the default GetCapabilities function for a processor. The default GetCapabilities function returns mutable capabilities.
type Traces ¶
type Traces interface {
internal.BaseConsumer
// ConsumeTraces processes the traces. After the function returns, the traces are no longer accessible,
// and accessing them is considered undefined behavior.
ConsumeTraces(ctx context.Context, td ptrace.Traces) error
}
Traces is an interface that receives ptrace.Traces, processes it as needed, and sends it to the next processing node if any or to the destination.
Directories
¶
| Path | Synopsis |
|---|---|
|
consumererror
module
|
|
|
consumererrorprofiles
module
|
|
|
xconsumererror
module
|
|
|
consumerprofiles
module
|
|
|
consumertest
module
|
|
|
xconsumer
module
|