forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
90 lines (80 loc) · 2.77 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package resourceprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourceprocessor"
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/processor/resourceprocessor/internal/metadata"
)
var processorCapabilities = consumer.Capabilities{MutatesData: true}
// NewFactory returns a new factory for the Resource processor.
func NewFactory() processor.Factory {
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithTraces(createTracesProcessor, metadata.TracesStability),
processor.WithMetrics(createMetricsProcessor, metadata.MetricsStability),
processor.WithLogs(createLogsProcessor, metadata.LogsStability))
}
// 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.CreateSettings,
cfg component.Config,
nextConsumer consumer.Traces) (processor.Traces, error) {
attrProc, err := attraction.NewAttrProc(&attraction.Settings{Actions: cfg.(*Config).AttributesActions})
if err != nil {
return nil, err
}
proc := &resourceProcessor{logger: set.Logger, attrProc: attrProc}
return processorhelper.NewTracesProcessor(
ctx,
set,
cfg,
nextConsumer,
proc.processTraces,
processorhelper.WithCapabilities(processorCapabilities))
}
func createMetricsProcessor(
ctx context.Context,
set processor.CreateSettings,
cfg component.Config,
nextConsumer consumer.Metrics) (processor.Metrics, error) {
attrProc, err := attraction.NewAttrProc(&attraction.Settings{Actions: cfg.(*Config).AttributesActions})
if err != nil {
return nil, err
}
proc := &resourceProcessor{logger: set.Logger, attrProc: attrProc}
return processorhelper.NewMetricsProcessor(
ctx,
set,
cfg,
nextConsumer,
proc.processMetrics,
processorhelper.WithCapabilities(processorCapabilities))
}
func createLogsProcessor(
ctx context.Context,
set processor.CreateSettings,
cfg component.Config,
nextConsumer consumer.Logs) (processor.Logs, error) {
attrProc, err := attraction.NewAttrProc(&attraction.Settings{Actions: cfg.(*Config).AttributesActions})
if err != nil {
return nil, err
}
proc := &resourceProcessor{logger: set.Logger, attrProc: attrProc}
return processorhelper.NewLogsProcessor(
ctx,
set,
cfg,
nextConsumer,
proc.processLogs,
processorhelper.WithCapabilities(processorCapabilities))
}