diff --git a/trace/otlp.go b/trace/otlp.go index 3ef028a..e3733c4 100644 --- a/trace/otlp.go +++ b/trace/otlp.go @@ -9,21 +9,19 @@ import ( ) // DefaultOtlpGrpcTimeout is the default timeout in seconds for the OTLP gRPC connection. -const DefaultOtlpGrpcTimeout = 5 +const DefaultOtlpGrpcTimeout = 30 -// NewOtlpGrpcClientConnection returns a gRPC connection, and accept a host and a list of [DialOption] -// -// [DialOption]: https://github.com/grpc/grpc-go +// NewOtlpGrpcClientConnection returns a gRPC connection, and accept a host and a list of [grpc.DialOption]. func NewOtlpGrpcClientConnection(ctx context.Context, host string, dialOptions ...grpc.DialOption) (*grpc.ClientConn, error) { dialCtx, cancel := context.WithTimeout(ctx, DefaultOtlpGrpcTimeout*time.Second) defer cancel() - if len(dialOptions) == 0 { - dialOptions = []grpc.DialOption{ - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), - } + dialContextOptions := []grpc.DialOption{ + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithBlock(), } - return grpc.DialContext(dialCtx, host, dialOptions...) + dialContextOptions = append(dialContextOptions, dialOptions...) + + return grpc.DialContext(dialCtx, host, dialContextOptions...) } diff --git a/trace/otlp_test.go b/trace/otlp_test.go index c1e701f..d688138 100644 --- a/trace/otlp_test.go +++ b/trace/otlp_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/grpc/connectivity" - "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/test/bufconn" ) @@ -35,8 +34,6 @@ func TestNewOtlpGrpcInsecureConnectionSuccess(t *testing.T) { context.Background(), "bufnet", grpc.WithContextDialer(bufDialer), - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithBlock(), ) assert.NoError(t, err) diff --git a/trace/processor.go b/trace/processor.go index 7d9bb67..89a887d 100644 --- a/trace/processor.go +++ b/trace/processor.go @@ -18,32 +18,24 @@ const ( Noop = "noop" // processor to void the trace spans ) -// NewTestSpanProcessor returns a [OTEL SpanProcessor] using a sync [tracetest.TestTraceExporter]. -// -// [OTEL SpanProcessor]: https://github.com/open-telemetry/opentelemetry-go +// NewTestSpanProcessor returns a [trace.SpanProcessor] using a sync [tracetest.TestTraceExporter]. func NewTestSpanProcessor(testTraceExporter tracetest.TestTraceExporter) trace.SpanProcessor { return trace.NewSimpleSpanProcessor(testTraceExporter) } -// NewNoopSpanProcessor returns a [OTEL SpanProcessor] that voids trace spans via an async [otelsdktracetest.NoopExporter]. -// -// [OTEL SpanProcessor]: https://github.com/open-telemetry/opentelemetry-go +// NewNoopSpanProcessor returns a [trace.SpanProcessor] that voids trace spans via an async [otelsdktracetest.NoopExporter]. func NewNoopSpanProcessor() trace.SpanProcessor { return trace.NewBatchSpanProcessor(otelsdktracetest.NewNoopExporter()) } -// NewTestSpanProcessor returns a [OTEL SpanProcessor] using an async [stdouttrace.Exporter]. -// -// [OTEL SpanProcessor]: https://github.com/open-telemetry/opentelemetry-go +// NewStdoutSpanProcessor returns a [trace.SpanProcessor] using an async [stdouttrace.Exporter]. func NewStdoutSpanProcessor(options ...stdouttrace.Option) trace.SpanProcessor { exporter, _ := stdouttrace.New(options...) return trace.NewBatchSpanProcessor(exporter) } -// NewOtlpGrpcSpanProcessor returns a [OTEL SpanProcessor] using an async [otlptracegrpc.Exporter]. -// -// [OTEL SpanProcessor]: https://github.com/open-telemetry/opentelemetry-go +// NewOtlpGrpcSpanProcessor returns a [trace.SpanProcessor] using an async [otlptracegrpc.Exporter]. func NewOtlpGrpcSpanProcessor(ctx context.Context, conn *grpc.ClientConn) (trace.SpanProcessor, error) { exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithGRPCConn(conn)) if err != nil {