| 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/plog" |
| 11 |
) |
| 12 |
|
| 13 |
// Logs is an interface that receives plog.Logs, processes it |
| 14 |
// as needed, and sends it to the next processing node if any or to the destination. |
| 15 |
type Logs interface { |
| 16 |
internal.BaseConsumer |
| 17 |
// ConsumeLogs processes the logs. After the function returns, the logs are no longer accessible, |
| 18 |
// and accessing them is considered undefined behavior. |
| 19 |
ConsumeLogs(ctx context.Context, ld plog.Logs) error |
| 20 |
} |
| 21 |
|
| 22 |
// ConsumeLogsFunc is a helper function that is similar to ConsumeLogs. |
| 23 |
type ConsumeLogsFunc func(ctx context.Context, ld plog.Logs) error |
| 24 |
|
| 25 |
// ConsumeLogs calls f(ctx, ld). |
| 26 |
func (f ConsumeLogsFunc) ConsumeLogs(ctx context.Context, ld plog.Logs) error { |
| 27 |
return f(ctx, ld) |
| 28 |
} |
| 29 |
|
| 30 |
type baseLogs struct { |
| 31 |
*internal.BaseImpl |
| 32 |
ConsumeLogsFunc |
| 33 |
} |
| 34 |
|
| 35 |
// NewLogs returns a Logs configured with the provided options. |
| 36 |
func NewLogs(consume ConsumeLogsFunc, options ...Option) (Logs, error) { |
| 37 |
if consume == nil { |
| 38 |
return nil, errNilFunc |
| 39 |
} |
| 40 |
return &baseLogs{ |
| 41 |
BaseImpl: internal.NewBaseImpl(options...), |
| 42 |
ConsumeLogsFunc: consume, |
| 43 |
}, nil |
| 44 |
} |