forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
55 lines (45 loc) · 1.5 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:generate mdatagen metadata.yaml
package redactionprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/redactionprocessor"
import (
"context"
"fmt"
"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/processor/redactionprocessor/internal/metadata"
)
// NewFactory creates a factory for the redaction processor.
func NewFactory() processor.Factory {
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithTraces(createTracesProcessor, metadata.TracesStability),
)
}
func createDefaultConfig() component.Config {
return &Config{}
}
// createTracesProcessor creates an instance of redaction for processing traces
func createTracesProcessor(
ctx context.Context,
set processor.CreateSettings,
cfg component.Config,
next consumer.Traces,
) (processor.Traces, error) {
oCfg := cfg.(*Config)
redaction, err := newRedaction(ctx, oCfg, set.Logger)
if err != nil {
// TODO: Placeholder for an error metric in the next PR
return nil, fmt.Errorf("error creating a redaction processor: %w", err)
}
return processorhelper.NewTracesProcessor(
ctx,
set,
cfg,
next,
redaction.processTraces,
processorhelper.WithCapabilities(consumer.Capabilities{MutatesData: true}))
}