Debian Codegraph @

otelcol/factories.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otelcol // import "go.opentelemetry.io/collector/otelcol"
5
6 import (
7 "fmt"
8
9 "go.opentelemetry.io/collector/component"
10 "go.opentelemetry.io/collector/connector"
11 "go.opentelemetry.io/collector/exporter"
12 "go.opentelemetry.io/collector/extension"
13 "go.opentelemetry.io/collector/processor"
14 "go.opentelemetry.io/collector/receiver"
15 "go.opentelemetry.io/collector/service/telemetry"
16 )
17
18 // Factories struct holds in a single type all component factories that
19 // can be handled by the Config.
20 type Factories struct {
21 // Receivers maps receiver type names in the config to the respective factory.
22 Receivers map[component.Type]receiver.Factory
23
24 // Processors maps processor type names in the config to the respective factory.
25 Processors map[component.Type]processor.Factory
26
27 // Exporters maps exporter type names in the config to the respective factory.
28 Exporters map[component.Type]exporter.Factory
29
30 // Extensions maps extension type names in the config to the respective factory.
31 Extensions map[component.Type]extension.Factory
32
33 // Connectors maps connector type names in the config to the respective factory.
34 Connectors map[component.Type]connector.Factory
35
36 // Telemetry is the factory to create the telemetry providers for the service.
37 Telemetry telemetry.Factory
38
39 // ReceiverModules maps receiver types to their respective go modules.
40 ReceiverModules map[component.Type]string
41
42 // ProcessorModules maps processor types to their respective go modules.
43 ProcessorModules map[component.Type]string
44
45 // ExporterModules maps exporter types to their respective go modules.
46 ExporterModules map[component.Type]string
47
48 // ExtensionModules maps extension types to their respective go modules.
49 ExtensionModules map[component.Type]string
50
51 // ConnectorModules maps connector types to their respective go modules.
52 ConnectorModules map[component.Type]string
53 }
54
55 // MakeFactoryMap takes a list of factories and returns a map with Factory type as keys.
56 // It returns a non-nil error when there are factories with duplicate type.
57 func MakeFactoryMap[T component.Factory](factories ...T) (map[component.Type]T, error) {
58 fMap := map[component.Type]T{}
59 for _, f := range factories {
60 if _, ok := fMap[f.Type()]; ok {
61 return fMap, fmt.Errorf("duplicate component factory %q", f.Type())
62 }
63 fMap[f.Type()] = f
64 }
65 return fMap, nil
66 }