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 (
|
||||||
@@ -35,7 +36,7 @@ func StartAgent(c Config) {
|
|||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
|
||||||
_, ok := agents[c.getEndpoint()]
|
_, ok := agents[c.Endpoint]
|
||||||
if ok {
|
if ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -45,7 +46,7 @@ func StartAgent(c Config) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
agents[c.getEndpoint()] = lang.Placeholder
|
agents[c.Endpoint] = lang.Placeholder
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopAgent shuts down the span processors in the order they were registered.
|
// StopAgent shuts down the span processors in the order they were registered.
|
||||||
@@ -57,10 +58,9 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|||||||
// Just support jaeger and zipkin now, more for later
|
// Just support jaeger and zipkin now, more for later
|
||||||
switch c.Batcher {
|
switch c.Batcher {
|
||||||
case kindJaeger:
|
case kindJaeger:
|
||||||
if c.isAgentEndPoint() {
|
|
||||||
return jaeger.New(jaeger.WithAgentEndpoint(jaeger.WithAgentHost(c.AgentHost), jaeger.WithAgentPort(c.AgentPort)))
|
|
||||||
}
|
|
||||||
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:
|
||||||
|
|||||||
@@ -11,12 +11,11 @@ func TestStartAgent(t *testing.T) {
|
|||||||
logx.Disable()
|
logx.Disable()
|
||||||
|
|
||||||
const (
|
const (
|
||||||
endpoint1 = "localhost:1234"
|
endpoint1 = "localhost:1234"
|
||||||
endpoint2 = "remotehost:1234"
|
endpoint2 = "remotehost:1234"
|
||||||
endpoint3 = "localhost:1235"
|
endpoint3 = "localhost:1235"
|
||||||
endpoint4 = "localhost:1236"
|
endpoint4 = "localhost:1236"
|
||||||
agentHost1 = "localhost"
|
endpoint5 = "localhost:6831"
|
||||||
agentPort1 = "6831"
|
|
||||||
)
|
)
|
||||||
c1 := Config{
|
c1 := Config{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
@@ -47,17 +46,9 @@ func TestStartAgent(t *testing.T) {
|
|||||||
Batcher: kindOtlpHttp,
|
Batcher: kindOtlpHttp,
|
||||||
}
|
}
|
||||||
c7 := Config{
|
c7 := Config{
|
||||||
Name: "jaegerUDP",
|
Name: "UDP",
|
||||||
AgentHost: agentHost1,
|
Endpoint: endpoint5,
|
||||||
AgentPort: agentPort1,
|
Batcher: kindJaegerUdp,
|
||||||
Batcher: kindJaeger,
|
|
||||||
}
|
|
||||||
c8 := Config{
|
|
||||||
Name: "jaegerUDP",
|
|
||||||
AgentHost: agentHost1,
|
|
||||||
AgentPort: agentPort1,
|
|
||||||
Endpoint: endpoint1,
|
|
||||||
Batcher: kindJaeger,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StartAgent(c1)
|
StartAgent(c1)
|
||||||
@@ -68,7 +59,6 @@ func TestStartAgent(t *testing.T) {
|
|||||||
StartAgent(c5)
|
StartAgent(c5)
|
||||||
StartAgent(c6)
|
StartAgent(c6)
|
||||||
StartAgent(c7)
|
StartAgent(c7)
|
||||||
StartAgent(c8)
|
|
||||||
|
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
@@ -81,12 +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[c2.getEndpoint()]
|
_, ok = agents[endpoint5]
|
||||||
assert.True(t, ok)
|
|
||||||
_, ok = agents[c3.getEndpoint()]
|
|
||||||
assert.False(t, ok)
|
|
||||||
_, ok = agents[c7.getEndpoint()]
|
|
||||||
assert.True(t, ok)
|
|
||||||
_, ok = agents[c8.getEndpoint()]
|
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,32 @@
|
|||||||
package trace
|
package trace
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// TraceName represents the tracing name.
|
// TraceName represents the tracing name.
|
||||||
const TraceName = "go-zero"
|
const TraceName = "go-zero"
|
||||||
|
|
||||||
// A Config is an opentelemetry config.
|
// A Config is an opentelemetry config.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `json:",optional"`
|
Name string `json:",optional"`
|
||||||
AgentHost string `json:",optional"`
|
Endpoint string `json:",optional"`
|
||||||
AgentPort string `json:",optional"`
|
Sampler float64 `json:",default=1.0"`
|
||||||
Endpoint string `json:",optional"`
|
Batcher string `json:",default=jaeger,options=jaeger|jaegerudp|zipkin|otlpgrpc|otlphttp"`
|
||||||
Sampler float64 `json:",default=1.0"`
|
|
||||||
Batcher string `json:",default=jaeger,options=jaeger|jaegerudp|zipkin|otlpgrpc|otlphttp"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) isAgentEndPoint() bool {
|
func (c *Config) getEndpointHost() string {
|
||||||
return len(c.AgentHost) != 0 && len(c.AgentPort) != 0
|
EndpointSlice := strings.Split(c.Endpoint, ":")
|
||||||
}
|
if len(EndpointSlice) > 0 {
|
||||||
|
return strings.TrimSpace(EndpointSlice[0])
|
||||||
func (c *Config) getEndpoint() string {
|
|
||||||
if c.isAgentEndPoint() {
|
|
||||||
return fmt.Sprintf("%s:%s", c.AgentHost, c.AgentPort)
|
|
||||||
}
|
}
|
||||||
return c.Endpoint
|
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