fix(trace): grpc exporter should use nonblock option (#2744)
* fix(trace): grpc exporter should use nonblock option * chore: sort imports
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/lang"
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"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"
|
||||||
@@ -14,7 +12,9 @@ import (
|
|||||||
"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"
|
||||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
"github.com/zeromicro/go-zero/core/lang"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -60,11 +60,15 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|||||||
case kindZipkin:
|
case kindZipkin:
|
||||||
return zipkin.New(c.Endpoint)
|
return zipkin.New(c.Endpoint)
|
||||||
case kindGrpc:
|
case kindGrpc:
|
||||||
|
// 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.
|
||||||
|
// If the connection not dial success, the global otel ErrorHandler will catch error
|
||||||
|
// when reporting data like other exporters.
|
||||||
return otlptracegrpc.New(
|
return otlptracegrpc.New(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
otlptracegrpc.WithInsecure(),
|
otlptracegrpc.WithInsecure(),
|
||||||
otlptracegrpc.WithEndpoint(c.Endpoint),
|
otlptracegrpc.WithEndpoint(c.Endpoint),
|
||||||
otlptracegrpc.WithDialOption(grpc.WithBlock()),
|
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown exporter: %s", c.Batcher)
|
return nil, fmt.Errorf("unknown exporter: %s", c.Batcher)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ func TestStartAgent(t *testing.T) {
|
|||||||
const (
|
const (
|
||||||
endpoint1 = "localhost:1234"
|
endpoint1 = "localhost:1234"
|
||||||
endpoint2 = "remotehost:1234"
|
endpoint2 = "remotehost:1234"
|
||||||
|
endpoint3 = "localhost:1235"
|
||||||
)
|
)
|
||||||
c1 := Config{
|
c1 := Config{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
@@ -29,12 +31,12 @@ func TestStartAgent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
c4 := Config{
|
c4 := Config{
|
||||||
Name: "bla",
|
Name: "bla",
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint3,
|
||||||
Batcher: "otlp",
|
Batcher: "otlp",
|
||||||
}
|
}
|
||||||
c5 := Config{
|
c5 := Config{
|
||||||
Name: "grpc",
|
Name: "grpc",
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint3,
|
||||||
Batcher: "grpc",
|
Batcher: "grpc",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ func TestStartAgent(t *testing.T) {
|
|||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
|
||||||
// because remotehost cannot be resolved
|
// because remotehost cannot be resolved
|
||||||
assert.Equal(t, 2, len(agents))
|
assert.Equal(t, 3, len(agents))
|
||||||
_, ok := agents[""]
|
_, ok := agents[""]
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
_, ok = agents[endpoint1]
|
_, ok = agents[endpoint1]
|
||||||
|
|||||||
Reference in New Issue
Block a user