mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-21 06:37:21 +00:00
Staticheck fixes
This commit is contained in:
+5
-13
@@ -12,8 +12,6 @@ import (
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type TracingSetup struct {
|
||||
@@ -27,23 +25,17 @@ type TraceSpanInfo struct {
|
||||
|
||||
// NewTracing creates a new tracing setup with OTLP exporter
|
||||
func NewTracing(ctx context.Context, endpoint string) (*TracingSetup, error) {
|
||||
if ctx == nil {
|
||||
return nil, fmt.Errorf("context cannot be nil")
|
||||
if ctx.Err() != nil {
|
||||
return nil, fmt.Errorf("invalid context: %v", ctx.Err())
|
||||
}
|
||||
if endpoint == "" {
|
||||
return nil, fmt.Errorf("endpoint cannot be empty")
|
||||
}
|
||||
|
||||
conn, err := grpc.DialContext(ctx, endpoint,
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithBlock(),
|
||||
grpc.WithReturnConnectionError(),
|
||||
exporter, err := otlptracegrpc.New(ctx,
|
||||
otlptracegrpc.WithEndpoint(endpoint),
|
||||
otlptracegrpc.WithInsecure(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create gRPC connection to collector: %w", err)
|
||||
}
|
||||
|
||||
exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithGRPCConn(conn))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create trace exporter: %w", err)
|
||||
}
|
||||
|
||||
@@ -65,10 +65,11 @@ func TestNewTracing(t *testing.T) {
|
||||
assert.Contains(t, err.Error(), "endpoint cannot be empty")
|
||||
})
|
||||
|
||||
t.Run("nil context", func(t *testing.T) {
|
||||
_, err := NewTracing(nil, "localhost:4317")
|
||||
assert.Error(t, err, "Expected error for nil context")
|
||||
assert.Contains(t, err.Error(), "context cannot be nil")
|
||||
t.Run("invalid context", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // Cancel the context immediately
|
||||
_, err := NewTracing(ctx, "localhost:4317")
|
||||
assert.Error(t, err, "Expected error for invalid context")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user