-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreceiver.go
145 lines (119 loc) · 3.93 KB
/
receiver.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package lightstepreceiver
import (
"context"
"fmt"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
"github.com/zalando/otelcol-lightstep-receiver/internal/lightstep_pb/grpc"
"github.com/zalando/otelcol-lightstep-receiver/internal/lightstep_pb/http"
"github.com/zalando/otelcol-lightstep-receiver/internal/lightstep_thrift"
"github.com/zalando/otelcol-lightstep-receiver/internal/metadata"
"github.com/zalando/otelcol-lightstep-receiver/internal/telemetry"
)
type lightstepReceiver struct {
cfg *Config
serverGRPC *grpc.ServerGRPC
serverPbHTTP *http.ServerHTTP
serverThrift *lightstep_thrift.ThriftServer
nextTraces consumer.Traces
logger *zap.Logger
settings *receiver.Settings
tracer trace.Tracer
obsrepGRPC *receiverhelper.ObsReport
obsrepPbHTTP *receiverhelper.ObsReport
obsrepThrift *receiverhelper.ObsReport
telemetry *telemetry.Telemetry
}
func (r *lightstepReceiver) Start(ctx context.Context, host component.Host) error {
r.logger.Info("starting servers")
var err error
if r.serverGRPC != nil {
if err = r.serverGRPC.Start(host); err != nil {
r.telemetry.Logger.Error("can't start grpc server", zap.Error(err))
return fmt.Errorf("can't start grpc server %s", err)
}
}
if r.serverPbHTTP != nil {
if err = r.serverPbHTTP.Start(ctx, host); err != nil {
r.telemetry.Logger.Error("can't start pb http server", zap.Error(err))
return fmt.Errorf("can't start pb http server %s", err)
}
}
if r.serverThrift != nil {
if err = r.serverThrift.Start(ctx, host); err != nil {
r.telemetry.Logger.Error("can't start thrift server", zap.Error(err))
return fmt.Errorf("can't start thrift server %s", err)
}
}
r.logger.Info("servers started")
return nil
}
func (r *lightstepReceiver) Shutdown(ctx context.Context) error {
var errs error
r.logger.Info("shutting down server")
if r.serverGRPC != nil {
r.serverGRPC.Shutdown()
}
if r.serverPbHTTP != nil {
r.serverPbHTTP.Shutdown(ctx)
}
if r.serverThrift != nil {
r.serverThrift.Shutdown(ctx)
}
return errs
}
func newLightstepReceiver(cfg *Config, set *receiver.Settings, nextTraces consumer.Traces) (*lightstepReceiver, error) {
var err error
r := &lightstepReceiver{
cfg: cfg,
serverGRPC: nil,
serverPbHTTP: nil,
serverThrift: nil,
nextTraces: nextTraces,
settings: set,
logger: nil,
tracer: set.TracerProvider.Tracer(metadata.Type.String()),
}
r.logger = set.Logger
r.telemetry = &telemetry.Telemetry{Name: metadata.Type.String()}
r.telemetry.Init(*set)
r.telemetry.Logger.Debug("config", zap.Any("config", cfg))
if cfg.PbGrpc != nil {
r.obsrepGRPC, err = receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: set.ID,
Transport: "pbgrpc",
ReceiverCreateSettings: *set,
})
if err != nil {
return nil, fmt.Errorf("can't init telemetry: %s", err)
}
r.serverGRPC = grpc.NewServer(cfg.PbGrpc, set, r.logger, nextTraces, r.obsrepGRPC, r.telemetry)
}
if cfg.PbHTTP != nil {
r.obsrepPbHTTP, err = receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: set.ID,
Transport: "pbhttp",
ReceiverCreateSettings: *set,
})
if err != nil {
return nil, fmt.Errorf("can't init telemetry: %s", err)
}
r.serverPbHTTP = http.NewServer(cfg.PbHTTP, set, nextTraces, r.obsrepPbHTTP, r.telemetry)
}
if cfg.Thrift != nil {
r.obsrepThrift, err = receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{
ReceiverID: set.ID,
Transport: "thrift",
ReceiverCreateSettings: *set,
})
if err != nil {
return nil, fmt.Errorf("can't init telemetry: %s", err)
}
r.serverThrift = lightstep_thrift.NewServer(cfg.Thrift, set, nextTraces, r.obsrepThrift, r.telemetry)
}
return r, nil
}