add kindJaegerUdp
This commit is contained in:
@@ -18,10 +18,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
kindJaeger = "jaeger"
|
||||
kindZipkin = "zipkin"
|
||||
kindOtlpGrpc = "otlpgrpc"
|
||||
kindOtlpHttp = "otlphttp"
|
||||
kindJaeger = "jaeger"
|
||||
kindJaegerUdp = "jaegerudp"
|
||||
kindZipkin = "zipkin"
|
||||
kindOtlpGrpc = "otlpgrpc"
|
||||
kindOtlpHttp = "otlphttp"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -58,6 +59,8 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
||||
switch c.Batcher {
|
||||
case kindJaeger:
|
||||
return jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(c.Endpoint)))
|
||||
case kindJaegerUdp:
|
||||
return jaeger.New(jaeger.WithAgentEndpoint(jaeger.WithAgentHost(c.getEndpointHost()), jaeger.WithAgentPort(c.getEndpointPort())))
|
||||
case kindZipkin:
|
||||
return zipkin.New(c.Endpoint)
|
||||
case kindOtlpGrpc:
|
||||
|
||||
@@ -15,6 +15,7 @@ func TestStartAgent(t *testing.T) {
|
||||
endpoint2 = "remotehost:1234"
|
||||
endpoint3 = "localhost:1235"
|
||||
endpoint4 = "localhost:1236"
|
||||
endpoint5 = "localhost:6831"
|
||||
)
|
||||
c1 := Config{
|
||||
Name: "foo",
|
||||
@@ -44,6 +45,11 @@ func TestStartAgent(t *testing.T) {
|
||||
Endpoint: endpoint4,
|
||||
Batcher: kindOtlpHttp,
|
||||
}
|
||||
c7 := Config{
|
||||
Name: "UDP",
|
||||
Endpoint: endpoint5,
|
||||
Batcher: kindJaegerUdp,
|
||||
}
|
||||
|
||||
StartAgent(c1)
|
||||
StartAgent(c1)
|
||||
@@ -52,6 +58,7 @@ func TestStartAgent(t *testing.T) {
|
||||
StartAgent(c4)
|
||||
StartAgent(c5)
|
||||
StartAgent(c6)
|
||||
StartAgent(c7)
|
||||
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
@@ -64,4 +71,6 @@ func TestStartAgent(t *testing.T) {
|
||||
assert.True(t, ok)
|
||||
_, ok = agents[endpoint2]
|
||||
assert.False(t, ok)
|
||||
_, ok = agents[endpoint5]
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package trace
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TraceName represents the tracing name.
|
||||
const TraceName = "go-zero"
|
||||
|
||||
@@ -8,5 +12,22 @@ type Config struct {
|
||||
Name string `json:",optional"`
|
||||
Endpoint string `json:",optional"`
|
||||
Sampler float64 `json:",default=1.0"`
|
||||
Batcher string `json:",default=jaeger,options=jaeger|zipkin|otlpgrpc|otlphttp"`
|
||||
Batcher string `json:",default=jaeger,options=jaeger|jaegerudp|zipkin|otlpgrpc|otlphttp"`
|
||||
}
|
||||
|
||||
func (c *Config) getEndpointHost() string {
|
||||
EndpointSlice := strings.Split(c.Endpoint, ":")
|
||||
if len(EndpointSlice) > 0 {
|
||||
return strings.TrimSpace(EndpointSlice[0])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *Config) getEndpointPort() string {
|
||||
EndpointSlice := strings.Split(c.Endpoint, ":")
|
||||
if len(EndpointSlice) > 1 {
|
||||
return strings.TrimSpace(EndpointSlice[1])
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user