fix(websocket): improve error type handling in connection establishment and ping monitoring

This commit is contained in:
Marc Schäfer
2025-10-08 08:14:04 +02:00
parent ae5129a7c7
commit fef9e8c76b

View File

@@ -20,6 +20,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"context" "context"
"github.com/fosrl/newt/internal/telemetry" "github.com/fosrl/newt/internal/telemetry"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )
@@ -448,9 +449,9 @@ conn, _, err := dialer.DialContext(spanCtx, u.String(), nil)
telemetry.IncConnError(context.Background(), "websocket", etype) telemetry.IncConnError(context.Background(), "websocket", etype)
telemetry.ObserveWSConnectLatency(context.Background(), lat, "failure", etype) telemetry.ObserveWSConnectLatency(context.Background(), lat, "failure", etype)
// Map handshake-related errors to reconnect reasons where appropriate // Map handshake-related errors to reconnect reasons where appropriate
if etype == "tls" { if etype == "tls_handshake" {
telemetry.IncReconnect(context.Background(), c.config.ID, "client", telemetry.ReasonHandshakeError) telemetry.IncReconnect(context.Background(), c.config.ID, "client", telemetry.ReasonHandshakeError)
} else if etype == "timeout" { } else if etype == "dial_timeout" {
telemetry.IncReconnect(context.Background(), c.config.ID, "client", telemetry.ReasonTimeout) telemetry.IncReconnect(context.Background(), c.config.ID, "client", telemetry.ReasonTimeout)
} else { } else {
telemetry.IncReconnect(context.Background(), c.config.ID, "client", telemetry.ReasonError) telemetry.IncReconnect(context.Background(), c.config.ID, "client", telemetry.ReasonError)