-
Notifications
You must be signed in to change notification settings - Fork 1
/
factory.go
69 lines (60 loc) · 1.88 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package leaderreceivercreator
import (
"context"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"github.com/skhalash/leaderreceivercreator/internal/sharedcomponent"
"github.com/skhalash/leaderreceivercreator/internal/metadata"
)
var receivers = sharedcomponent.NewSharedComponents()
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithLogs(createLogsReceiver, metadata.LogsStability),
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
receiver.WithTraces(createTracesReceiver, metadata.TracesStability),
)
}
func createDefaultConfig() component.Config {
return &Config{}
}
func createLogsReceiver(
_ context.Context,
params receiver.CreateSettings,
cfg component.Config,
consumer consumer.Logs,
) (receiver.Logs, error) {
r := receivers.GetOrAdd(cfg, func() component.Component {
return newLeaderReceiverCreator(params, cfg.(*Config))
})
r.Component.(*leaderReceiverCreator).nextLogsConsumer = consumer
return r, nil
}
func createMetricsReceiver(
_ context.Context,
params receiver.CreateSettings,
cfg component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
r := receivers.GetOrAdd(cfg, func() component.Component {
return newLeaderReceiverCreator(params, cfg.(*Config))
})
r.Component.(*leaderReceiverCreator).nextMetricsConsumer = consumer
return r, nil
}
func createTracesReceiver(
_ context.Context,
params receiver.CreateSettings,
cfg component.Config,
consumer consumer.Traces,
) (receiver.Traces, error) {
r := receivers.GetOrAdd(cfg, func() component.Component {
return newLeaderReceiverCreator(params, cfg.(*Config))
})
r.Component.(*leaderReceiverCreator).nextTracesConsumer = consumer
return r, nil
}