-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
factory.go
105 lines (93 loc) · 2.73 KB
/
factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:generate mdatagen metadata.yaml
package schemaprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor"
import (
"context"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor/internal/metadata"
)
var processorCapabilities = consumer.Capabilities{MutatesData: true}
// factory will store any of the precompiled schemas in future
type factory struct{}
// newDefaultConfiguration returns the configuration for schema transformer processor
// with the default values being used throughout it
func newDefaultConfiguration() component.Config {
return &Config{
ClientConfig: confighttp.NewDefaultClientConfig(),
}
}
func NewFactory() processor.Factory {
f := &factory{}
return processor.NewFactory(
metadata.Type,
newDefaultConfiguration,
processor.WithLogs(f.createLogsProcessor, metadata.LogsStability),
processor.WithMetrics(f.createMetricsProcessor, metadata.MetricsStability),
processor.WithTraces(f.createTracesProcessor, metadata.TracesStability),
)
}
func (f factory) createLogsProcessor(
ctx context.Context,
set processor.CreateSettings,
cfg component.Config,
next consumer.Logs,
) (processor.Logs, error) {
transformer, err := newTransformer(ctx, cfg, set)
if err != nil {
return nil, err
}
return processorhelper.NewLogsProcessor(
ctx,
set,
cfg,
next,
transformer.processLogs,
processorhelper.WithCapabilities(processorCapabilities),
processorhelper.WithStart(transformer.start),
)
}
func (f factory) createMetricsProcessor(
ctx context.Context,
set processor.CreateSettings,
cfg component.Config,
next consumer.Metrics,
) (processor.Metrics, error) {
transformer, err := newTransformer(ctx, cfg, set)
if err != nil {
return nil, err
}
return processorhelper.NewMetricsProcessor(
ctx,
set,
cfg,
next,
transformer.processMetrics,
processorhelper.WithCapabilities(processorCapabilities),
processorhelper.WithStart(transformer.start),
)
}
func (f factory) createTracesProcessor(
ctx context.Context,
set processor.CreateSettings,
cfg component.Config,
next consumer.Traces,
) (processor.Traces, error) {
transformer, err := newTransformer(ctx, cfg, set)
if err != nil {
return nil, err
}
return processorhelper.NewTracesProcessor(
ctx,
set,
cfg,
next,
transformer.processTraces,
processorhelper.WithCapabilities(processorCapabilities),
processorhelper.WithStart(transformer.start),
)
}