-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
factory.go
117 lines (102 loc) · 3.41 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
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package attributesprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor"
import (
"context"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/attraction"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterlog"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filtermetric"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterspan"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor/internal/metadata"
)
var processorCapabilities = consumer.Capabilities{MutatesData: true}
// NewFactory returns a new factory for the Attributes processor.
func NewFactory() processor.Factory {
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithTraces(createTracesProcessor, metadata.TracesStability),
processor.WithLogs(createLogsProcessor, metadata.LogsStability),
processor.WithMetrics(createMetricsProcessor, metadata.MetricsStability))
}
// Note: This isn't a valid configuration because the processor would do no work.
func createDefaultConfig() component.Config {
return &Config{}
}
func createTracesProcessor(
ctx context.Context,
set processor.Settings,
cfg component.Config,
nextConsumer consumer.Traces,
) (processor.Traces, error) {
oCfg := cfg.(*Config)
attrProc, err := attraction.NewAttrProc(&oCfg.Settings)
if err != nil {
return nil, err
}
skipExpr, err := filterspan.NewSkipExpr(&oCfg.MatchConfig)
if err != nil {
return nil, err
}
return processorhelper.NewTracesProcessor(
ctx,
set,
cfg,
nextConsumer,
newSpanAttributesProcessor(set.Logger, attrProc, skipExpr).processTraces,
processorhelper.WithCapabilities(processorCapabilities))
}
func createLogsProcessor(
ctx context.Context,
set processor.Settings,
cfg component.Config,
nextConsumer consumer.Logs,
) (processor.Logs, error) {
oCfg := cfg.(*Config)
attrProc, err := attraction.NewAttrProc(&oCfg.Settings)
if err != nil {
return nil, err
}
skipExpr, err := filterlog.NewSkipExpr(&oCfg.MatchConfig)
if err != nil {
return nil, err
}
return processorhelper.NewLogsProcessor(
ctx,
set,
cfg,
nextConsumer,
newLogAttributesProcessor(set.Logger, attrProc, skipExpr).processLogs,
processorhelper.WithCapabilities(processorCapabilities))
}
func createMetricsProcessor(
ctx context.Context,
set processor.Settings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (processor.Metrics, error) {
oCfg := cfg.(*Config)
attrProc, err := attraction.NewAttrProc(&oCfg.Settings)
if err != nil {
return nil, err
}
skipExpr, err := filtermetric.NewSkipExpr(
filterconfig.CreateMetricMatchPropertiesFromDefault(oCfg.Include),
filterconfig.CreateMetricMatchPropertiesFromDefault(oCfg.Exclude),
)
if err != nil {
return nil, err
}
return processorhelper.NewMetricsProcessor(
ctx,
set,
cfg,
nextConsumer,
newMetricAttributesProcessor(set.Logger, attrProc, skipExpr).processMetrics,
processorhelper.WithCapabilities(processorCapabilities))
}