Debian Codegraph @

processor/processortest/nop_processor.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package processortest // import "go.opentelemetry.io/collector/processor/processortest"
5
6 import (
7 "context"
8
9 "go.opentelemetry.io/collector/component"
10 "go.opentelemetry.io/collector/component/componenttest"
11 "go.opentelemetry.io/collector/consumer"
12 "go.opentelemetry.io/collector/consumer/consumertest"
13 "go.opentelemetry.io/collector/consumer/xconsumer"
14 "go.opentelemetry.io/collector/processor"
15 "go.opentelemetry.io/collector/processor/xprocessor"
16 )
17
18 var NopType = component.MustNewType("nop")
19
20 // NewNopSettings returns a new nop settings for Create* functions with the given type.
21 func NewNopSettings(typ component.Type) processor.Settings {
22 return processor.Settings{
23 ID: component.NewID(typ),
24 TelemetrySettings: componenttest.NewNopTelemetrySettings(),
25 BuildInfo: component.NewDefaultBuildInfo(),
26 }
27 }
28
29 // NewNopFactory returns a component.ProcessorFactory that constructs nop processors.
30 func NewNopFactory() processor.Factory {
31 return xprocessor.NewFactory(
32 NopType,
33 func() component.Config { return &nopConfig{} },
34 xprocessor.WithTraces(createTraces, component.StabilityLevelStable),
35 xprocessor.WithMetrics(createMetrics, component.StabilityLevelStable),
36 xprocessor.WithLogs(createLogs, component.StabilityLevelStable),
37 xprocessor.WithProfiles(createProfiles, component.StabilityLevelAlpha),
38 )
39 }
40
41 func createTraces(context.Context, processor.Settings, component.Config, consumer.Traces) (processor.Traces, error) {
42 return nopInstance, nil
43 }
44
45 func createMetrics(context.Context, processor.Settings, component.Config, consumer.Metrics) (processor.Metrics, error) {
46 return nopInstance, nil
47 }
48
49 func createLogs(context.Context, processor.Settings, component.Config, consumer.Logs) (processor.Logs, error) {
50 return nopInstance, nil
51 }
52
53 func createProfiles(context.Context, processor.Settings, component.Config, xconsumer.Profiles) (xprocessor.Profiles, error) {
54 return nopInstance, nil
55 }
56
57 type nopConfig struct{}
58
59 var nopInstance = &nop{
60 Consumer: consumertest.NewNop(),
61 }
62
63 // nop acts as a processor for testing purposes.
64 type nop struct {
65 component.StartFunc
66 component.ShutdownFunc
67 consumertest.Consumer
68 }