-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
factory.go
139 lines (115 loc) · 4.37 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
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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package jaegerreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver"
// This file implements factory for Jaeger receiver.
import (
"context"
"sync"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/receiver"
"go.uber.org/zap"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/jaegerreceiverdeprecated"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver/internal/metadata"
)
const (
// Protocol values.
protoGRPC = "grpc"
protoThriftHTTP = "thrift_http"
protoThriftBinary = "thrift_binary"
protoThriftCompact = "thrift_compact"
// Default endpoints to bind to.
defaultGRPCBindEndpoint = "0.0.0.0:14250"
defaultHTTPBindEndpoint = "0.0.0.0:14268"
defaultThriftCompactBindEndpoint = "0.0.0.0:6831"
defaultThriftBinaryBindEndpoint = "0.0.0.0:6832"
)
var disableJaegerReceiverRemoteSampling = featuregate.GlobalRegistry().MustRegister(
"receiver.jaeger.DisableRemoteSampling",
featuregate.StageBeta,
featuregate.WithRegisterDescription("When enabled, the Jaeger Receiver will fail to start when it is configured with remote_sampling config. When disabled, the receiver will start and the remote_sampling config will be no-op."),
)
var once sync.Once
func logDeprecation(logger *zap.Logger) {
once.Do(func() {
logger.Warn("jaeger receiver will deprecate Thrift-gen and replace it with Proto-gen to be compatbible to jaeger 1.42.0 and higher. See https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/18485 for more details.")
})
}
const protoInsteadOfThrift = "receiver.jaegerreceiver.replaceThriftWithProto"
var protoGate = featuregate.GlobalRegistry().MustRegister(
protoInsteadOfThrift,
featuregate.StageBeta,
featuregate.WithRegisterDescription(
"When enabled, the jaegerreceiver will use Proto-gen over Thrift-gen.",
),
)
// NewFactory creates a new Jaeger receiver factory.
func NewFactory() receiver.Factory {
if !protoGate.IsEnabled() {
return jaegerreceiverdeprecated.NewFactory()
}
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithTraces(createTracesReceiver, metadata.TracesStability))
}
// CreateDefaultConfig creates the default configuration for Jaeger receiver.
func createDefaultConfig() component.Config {
return &Config{
Protocols: Protocols{
GRPC: &configgrpc.GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: defaultGRPCBindEndpoint,
Transport: "tcp",
},
},
ThriftHTTP: &confighttp.HTTPServerSettings{
Endpoint: defaultHTTPBindEndpoint,
},
ThriftBinary: &ProtocolUDP{
Endpoint: defaultThriftBinaryBindEndpoint,
ServerConfigUDP: defaultServerConfigUDP(),
},
ThriftCompact: &ProtocolUDP{
Endpoint: defaultThriftCompactBindEndpoint,
ServerConfigUDP: defaultServerConfigUDP(),
},
},
}
}
// createTracesReceiver creates a trace receiver based on provided config.
func createTracesReceiver(
_ context.Context,
set receiver.CreateSettings,
cfg component.Config,
nextConsumer consumer.Traces,
) (receiver.Traces, error) {
logDeprecation(set.Logger)
// Convert settings in the source config to configuration struct
// that Jaeger receiver understands.
// Error handling for the conversion is done in the Validate function from the Config object itself.
rCfg := cfg.(*Config)
var config configuration
// Set ports
if rCfg.Protocols.GRPC != nil {
config.CollectorGRPCServerSettings = *rCfg.Protocols.GRPC
}
if rCfg.Protocols.ThriftHTTP != nil {
config.CollectorHTTPSettings = *rCfg.ThriftHTTP
}
if rCfg.Protocols.ThriftBinary != nil {
config.AgentBinaryThrift = *rCfg.ThriftBinary
}
if rCfg.Protocols.ThriftCompact != nil {
config.AgentCompactThrift = *rCfg.ThriftCompact
}
if rCfg.RemoteSampling != nil {
set.Logger.Warn("You are using a deprecated no-op `remote_sampling` option which will be removed soon; use a `jaegerremotesampling` extension instead")
}
// Create the receiver.
return newJaegerReceiver(set.ID, &config, nextConsumer, set)
}