mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
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:
parent
ec7ac43948
commit
42413dc294
@ -10,6 +10,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/exporters/jaeger"
|
"go.opentelemetry.io/otel/exporters/jaeger"
|
||||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
"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/exporters/zipkin"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
@ -19,7 +20,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
kindJaeger = "jaeger"
|
kindJaeger = "jaeger"
|
||||||
kindZipkin = "zipkin"
|
kindZipkin = "zipkin"
|
||||||
kindGrpc = "grpc"
|
kindOtlpGrpc = "otlpgrpc"
|
||||||
|
kindOtlpHttp = "otlphttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -58,7 +60,7 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|||||||
return jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(c.Endpoint)))
|
return jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(c.Endpoint)))
|
||||||
case kindZipkin:
|
case kindZipkin:
|
||||||
return zipkin.New(c.Endpoint)
|
return zipkin.New(c.Endpoint)
|
||||||
case kindGrpc:
|
case kindOtlpGrpc:
|
||||||
// Always treat trace exporter as optional component, so we use nonblock here,
|
// 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
|
// otherwise this would slow down app start up even set a dial timeout here when
|
||||||
// endpoint can not reach.
|
// endpoint can not reach.
|
||||||
@ -69,6 +71,13 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|||||||
otlptracegrpc.WithInsecure(),
|
otlptracegrpc.WithInsecure(),
|
||||||
otlptracegrpc.WithEndpoint(c.Endpoint),
|
otlptracegrpc.WithEndpoint(c.Endpoint),
|
||||||
)
|
)
|
||||||
|
case kindOtlpHttp:
|
||||||
|
// Not support flexible configuration now.
|
||||||
|
return otlptracehttp.New(
|
||||||
|
context.Background(),
|
||||||
|
otlptracehttp.WithInsecure(),
|
||||||
|
otlptracehttp.WithEndpoint(c.Endpoint),
|
||||||
|
)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown exporter: %s", c.Batcher)
|
return nil, fmt.Errorf("unknown exporter: %s", c.Batcher)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ func TestStartAgent(t *testing.T) {
|
|||||||
endpoint1 = "localhost:1234"
|
endpoint1 = "localhost:1234"
|
||||||
endpoint2 = "remotehost:1234"
|
endpoint2 = "remotehost:1234"
|
||||||
endpoint3 = "localhost:1235"
|
endpoint3 = "localhost:1235"
|
||||||
|
endpoint4 = "localhost:1236"
|
||||||
)
|
)
|
||||||
c1 := Config{
|
c1 := Config{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
@ -36,7 +37,12 @@ func TestStartAgent(t *testing.T) {
|
|||||||
c5 := Config{
|
c5 := Config{
|
||||||
Name: "grpc",
|
Name: "grpc",
|
||||||
Endpoint: endpoint3,
|
Endpoint: endpoint3,
|
||||||
Batcher: "grpc",
|
Batcher: kindOtlpGrpc,
|
||||||
|
}
|
||||||
|
c6 := Config{
|
||||||
|
Name: "otlphttp",
|
||||||
|
Endpoint: endpoint4,
|
||||||
|
Batcher: kindOtlpHttp,
|
||||||
}
|
}
|
||||||
|
|
||||||
StartAgent(c1)
|
StartAgent(c1)
|
||||||
@ -45,12 +51,13 @@ func TestStartAgent(t *testing.T) {
|
|||||||
StartAgent(c3)
|
StartAgent(c3)
|
||||||
StartAgent(c4)
|
StartAgent(c4)
|
||||||
StartAgent(c5)
|
StartAgent(c5)
|
||||||
|
StartAgent(c6)
|
||||||
|
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
|
||||||
// because remotehost cannot be resolved
|
// because remotehost cannot be resolved
|
||||||
assert.Equal(t, 3, len(agents))
|
assert.Equal(t, 4, len(agents))
|
||||||
_, ok := agents[""]
|
_, ok := agents[""]
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
_, ok = agents[endpoint1]
|
_, ok = agents[endpoint1]
|
||||||
|
@ -8,5 +8,5 @@ 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|grpc"`
|
Batcher string `json:",default=jaeger,options=jaeger|zipkin|otlpgrpc|otlphttp"`
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -28,6 +28,7 @@ require (
|
|||||||
go.opentelemetry.io/otel v1.10.0
|
go.opentelemetry.io/otel v1.10.0
|
||||||
go.opentelemetry.io/otel/exporters/jaeger 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/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/exporters/zipkin v1.10.0
|
||||||
go.opentelemetry.io/otel/sdk v1.10.0
|
go.opentelemetry.io/otel/sdk v1.10.0
|
||||||
go.opentelemetry.io/otel/trace v1.10.0
|
go.opentelemetry.io/otel/trace v1.10.0
|
||||||
|
2
go.sum
2
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 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 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/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 h1:HcPAFsFpEBKF+G5NIOA+gBsxifd3Ej+wb+KsdBLa15E=
|
||||||
go.opentelemetry.io/otel/exporters/zipkin v1.10.0/go.mod h1:HdfvgwcOoCB0+zzrTHycW6btjK0zNpkz2oTGO815SCI=
|
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=
|
go.opentelemetry.io/otel/sdk v1.10.0 h1:jZ6K7sVn04kk/3DNUdJ4mqRlGDiXAVuIG+MMENpTNdY=
|
||||||
|
Loading…
Reference in New Issue
Block a user