diff --git a/core/trace/agent.go b/core/trace/agent.go index 668ae7ed..6fbe2e78 100644 --- a/core/trace/agent.go +++ b/core/trace/agent.go @@ -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) } diff --git a/core/trace/agent_test.go b/core/trace/agent_test.go index bd3810b4..1d20694e 100644 --- a/core/trace/agent_test.go +++ b/core/trace/agent_test.go @@ -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] diff --git a/core/trace/config.go b/core/trace/config.go index 099573b9..83c62c3c 100644 --- a/core/trace/config.go +++ b/core/trace/config.go @@ -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"` } diff --git a/go.mod b/go.mod index 60281d3e..16c20409 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( go.opentelemetry.io/otel v1.10.0 go.opentelemetry.io/otel/exporters/jaeger v1.10.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.10.0 go.opentelemetry.io/otel/exporters/zipkin v1.10.0 go.opentelemetry.io/otel/sdk v1.10.0 go.opentelemetry.io/otel/trace v1.10.0 diff --git a/go.sum b/go.sum index cd3d0509..94cf1c2a 100644 --- a/go.sum +++ b/go.sum @@ -860,6 +860,8 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 h1:pDDYmo0QadUPal5fwXo go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0/go.mod h1:Krqnjl22jUJ0HgMzw5eveuCvFDXY4nSYb4F8t5gdrag= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 h1:KtiUEhQmj/Pa874bVYKGNVdq8NPKiacPbaRRtgXi+t4= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0/go.mod h1:OfUCyyIiDvNXHWpcWgbF+MWvqPZiNa3YDEnivcnYsV0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.10.0 h1:S8DedULB3gp93Rh+9Z+7NTEv+6Id/KYS7LDyipZ9iCE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.10.0/go.mod h1:5WV40MLWwvWlGP7Xm8g3pMcg0pKOUY609qxJn8y7LmM= go.opentelemetry.io/otel/exporters/zipkin v1.10.0 h1:HcPAFsFpEBKF+G5NIOA+gBsxifd3Ej+wb+KsdBLa15E= go.opentelemetry.io/otel/exporters/zipkin v1.10.0/go.mod h1:HdfvgwcOoCB0+zzrTHycW6btjK0zNpkz2oTGO815SCI= go.opentelemetry.io/otel/sdk v1.10.0 h1:jZ6K7sVn04kk/3DNUdJ4mqRlGDiXAVuIG+MMENpTNdY=