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