| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
//go:generate mdatagen metadata.yaml |
| 5 |
|
| 6 |
package batchprocessor // import "go.opentelemetry.io/collector/processor/batchprocessor" |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"time" |
| 11 |
|
| 12 |
"go.opentelemetry.io/collector/component" |
| 13 |
"go.opentelemetry.io/collector/consumer" |
| 14 |
"go.opentelemetry.io/collector/processor" |
| 15 |
"go.opentelemetry.io/collector/processor/batchprocessor/internal/metadata" |
| 16 |
) |
| 17 |
|
| 18 |
const ( |
| 19 |
defaultSendBatchSize = uint32(8192) |
| 20 |
defaultTimeout = 200 * time.Millisecond |
| 21 |
|
| 22 |
// defaultMetadataCardinalityLimit should be set to the number |
| 23 |
// of metadata configurations the user expects to submit to |
| 24 |
// the collector. |
| 25 |
defaultMetadataCardinalityLimit = 1000 |
| 26 |
) |
| 27 |
|
| 28 |
// NewFactory returns a new factory for the Batch processor. |
| 29 |
func NewFactory() processor.Factory { |
| 30 |
return processor.NewFactory( |
| 31 |
metadata.Type, |
| 32 |
createDefaultConfig, |
| 33 |
processor.WithTraces(createTraces, metadata.TracesStability), |
| 34 |
processor.WithMetrics(createMetrics, metadata.MetricsStability), |
| 35 |
processor.WithLogs(createLogs, metadata.LogsStability)) |
| 36 |
} |
| 37 |
|
| 38 |
func createDefaultConfig() component.Config { |
| 39 |
return &Config{ |
| 40 |
SendBatchSize: defaultSendBatchSize, |
| 41 |
Timeout: defaultTimeout, |
| 42 |
MetadataCardinalityLimit: defaultMetadataCardinalityLimit, |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func createTraces( |
| 47 |
_ context.Context, |
| 48 |
set processor.Settings, |
| 49 |
cfg component.Config, |
| 50 |
nextConsumer consumer.Traces, |
| 51 |
) (processor.Traces, error) { |
| 52 |
return newTracesBatchProcessor(set, nextConsumer, cfg.(*Config)) |
| 53 |
} |
| 54 |
|
| 55 |
func createMetrics( |
| 56 |
_ context.Context, |
| 57 |
set processor.Settings, |
| 58 |
cfg component.Config, |
| 59 |
nextConsumer consumer.Metrics, |
| 60 |
) (processor.Metrics, error) { |
| 61 |
return newMetricsBatchProcessor(set, nextConsumer, cfg.(*Config)) |
| 62 |
} |
| 63 |
|
| 64 |
func createLogs( |
| 65 |
_ context.Context, |
| 66 |
set processor.Settings, |
| 67 |
cfg component.Config, |
| 68 |
nextConsumer consumer.Logs, |
| 69 |
) (processor.Logs, error) { |
| 70 |
return newLogsBatchProcessor(set, nextConsumer, cfg.(*Config)) |
| 71 |
} |