sql-pg: trace each connection attempt, with why it failed

Aperta
#10,951 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
observability

Direzione di ricerca

Start by reading the existing db.connect span behavior in @effect/sql-pg and the PgConnection connection-attempt flow. Check how password resolution, timeout, authentication, interruption, and ReadyForQuery are handled, then compare the proposed span and failure categories with project conventions. Done means the maintainers agree on the API shape and a PR covers per-attempt tracing without changing pool behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Note: everything below was written by an AI agent working on the author's behalf and may not have been reviewed by a human.

This is AI-generated; I don't have strong opinions on the API or developer experience and am glad to take whatever shape you prefer, but I do need the functionality.

Problem

With SpanPropagationEnabled, @effect/sql-pg adds a db.connect child span to a statement that waited for a new session (#8676), covering the part of the connect it waited for. A connection attempt has no span of its own, so these are invisible in a trace:

  • an attempt that fails, and why: a timeout, a refused or unreachable host, an authentication failure, or something else;
  • an attempt that no statement waited for, such as one the pool opens ahead of demand;
  • how long password resolution, the TCP/TLS connect and authentication took, until ReadyForQuery.

On serverless Postgres behind a proxy, failed and slow connects are exactly what I need to see when the first query of a request is slow.

What I do today

I carry a patch to PgConnection that wraps each connection attempt in a client span, sql.connect:

  • It covers password resolution, the driver's connect and authentication, and connectTimeout, and ends at ReadyForQuery, or on failure or interruption. The timeout runs inside the span, so a timed-out attempt fails its span instead of ending OK.
  • It records db.connect.attempt and, on failure, db.connect.failure: timeout, refused (the socket never connected, or the server refused the startup for a reason other than authentication), auth (SQLSTATE class 28, or no password), or other. The category comes from when the attempt failed, not from the socket error's text, because some runtimes give a refused connection no error code.
  • It records no URL, credentials or query text. An attempt its caller interrupts records no failure.
  • Pool behaviour (lazy acquisition, reuse, idle release) is unchanged, and it opens no connection to measure one.

Questions

  1. Would you take a per-attempt span in @effect/sql-pg, alongside the existing db.connect?
  2. Are a span name sql.connect and the attributes db.connect.attempt / db.connect.failure acceptable, or would you rather follow another convention?

I can open a PR once the shape is agreed.

Lingua principale
TypeScript
Stelle
16.7k
Fork
808
Merge medio
21h 22m
PR unite (30g)
486

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Effect-TS/effect

Tutte le issue di Effect-TS/effect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.