feat(trace): support otlp http exporter (#2746)
* feat(trace): support otlp http exporter * chore: use otlptracehttp v1.10.0 not upgrade grpc version prevent other modules break * refactor(trace): rename exporter kind grpc to otlpgrpc. BREAKING CHANGE: trace Config.Batcher should use otlpgrpc instead of grpc now.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/jaeger"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
|
||||
"go.opentelemetry.io/otel/exporters/zipkin"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
@@ -17,9 +18,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
kindJaeger = "jaeger"
|
||||
kindZipkin = "zipkin"
|
||||
kindGrpc = "grpc"
|
||||
kindJaeger = "jaeger"
|
||||
kindZipkin = "zipkin"
|
||||
kindOtlpGrpc = "otlpgrpc"
|
||||
kindOtlpHttp = "otlphttp"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -58,7 +60,7 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
||||
return jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(c.Endpoint)))
|
||||
case kindZipkin:
|
||||
return zipkin.New(c.Endpoint)
|
||||
case kindGrpc:
|
||||
case kindOtlpGrpc:
|
||||
// Always treat trace exporter as optional component, so we use nonblock here,
|
||||
// otherwise this would slow down app start up even set a dial timeout here when
|
||||
// endpoint can not reach.
|
||||
@@ -69,6 +71,13 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
||||
otlptracegrpc.WithInsecure(),
|
||||
otlptracegrpc.WithEndpoint(c.Endpoint),
|
||||
)
|
||||
case kindOtlpHttp:
|
||||
// Not support flexible configuration now.
|
||||
return otlptracehttp.New(
|
||||
context.Background(),
|
||||
otlptracehttp.WithInsecure(),
|
||||
otlptracehttp.WithEndpoint(c.Endpoint),
|
||||
)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown exporter: %s", c.Batcher)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func TestStartAgent(t *testing.T) {
|
||||
endpoint1 = "localhost:1234"
|
||||
endpoint2 = "remotehost:1234"
|
||||
endpoint3 = "localhost:1235"
|
||||
endpoint4 = "localhost:1236"
|
||||
)
|
||||
c1 := Config{
|
||||
Name: "foo",
|
||||
@@ -36,7 +37,12 @@ func TestStartAgent(t *testing.T) {
|
||||
c5 := Config{
|
||||
Name: "grpc",
|
||||
Endpoint: endpoint3,
|
||||
Batcher: "grpc",
|
||||
Batcher: kindOtlpGrpc,
|
||||
}
|
||||
c6 := Config{
|
||||
Name: "otlphttp",
|
||||
Endpoint: endpoint4,
|
||||
Batcher: kindOtlpHttp,
|
||||
}
|
||||
|
||||
StartAgent(c1)
|
||||
@@ -45,12 +51,13 @@ func TestStartAgent(t *testing.T) {
|
||||
StartAgent(c3)
|
||||
StartAgent(c4)
|
||||
StartAgent(c5)
|
||||
StartAgent(c6)
|
||||
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
// because remotehost cannot be resolved
|
||||
assert.Equal(t, 3, len(agents))
|
||||
assert.Equal(t, 4, len(agents))
|
||||
_, ok := agents[""]
|
||||
assert.True(t, ok)
|
||||
_, ok = agents[endpoint1]
|
||||
|
||||
@@ -8,5 +8,5 @@ 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|grpc"`
|
||||
Batcher string `json:",default=jaeger,options=jaeger|zipkin|otlpgrpc|otlphttp"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user