{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package dbtrace\n\nPackage dbtrace counts database calls per request and logs the heavy ones. It is off until Configure enables it; the hot-path helpers are no-ops for contexts without a tracker.\n\nConnection use per request ≈ tx + pooled + raw (each pooled/raw call takes its own pool connection; calls inside RunInTransaction share the tx's).\n\n## Functions\n\n```go\nfunc Configure(o Options)\n```\nConfigure sets the active options. Safe to call at any time.\n\n```go\nfunc Enabled() bool\n```\nEnabled reports whether per-request tracing is on.\n\n```go\nfunc Middleware(next http.Handler) http.Handler\n```\nMiddleware tracks every request and logs those over the configured thresholds once the handler returns. Options are read per request, so Configure can toggle it at runtime. Raw calls made by detached goroutines after the response (e.g. session activity) are not included in the log line.\n\n```go\nfunc PoolLogEnabled() bool\n```\nPoolLogEnabled reports whether pool logging is on.\n\n```go\nfunc Query(ctx context.Context)\n```\nQuery counts one adapter query.\n\n```go\nfunc Raw(ctx context.Context, kind string)\n```\nRaw counts one direct \\*sql.DB call, labelled by what issued it.\n\n```go\nfunc TxBegin(ctx context.Context) func()\n```\nTxBegin counts a transaction and returns a func to call when it ends. Queries between the two are attributed to the transaction's connection.\n\n## Types\n\n```go\ntype Options struct {\n\tEnabled     bool\n\tMinCalls    int           // log when tx+pooled+raw \u003e= MinCalls\n\tMinDuration time.Duration // or when the request took at least this (0 = off)\n\tPoolLog     bool          // log pool deltas on each dbmanager metrics publish\n}\n```\nOptions controls tracing.\n\n```go\nfunc FromConfig(c config.DBTraceConfig) Options\n```\nFromConfig maps the application config to Options.\n\n```go\ntype Tracker struct {\n\t// contains filtered or unexported fields\n}\n```\nTracker holds one request's counters.\n\n```go\nfunc From(ctx context.Context) *Tracker\n```\nFrom returns the Tracker on ctx, or nil.\n\n```go\nfunc Start(ctx context.Context) (context.Context, *Tracker)\n```\nStart attaches a new Tracker to ctx.\n\n```go\nfunc (t *Tracker) Summary() string\n```\nSummary renders the counters, e.g. \"tx=1 tx\\_queries=3 pooled=2 raw=1 \\[auth.session=1]\".\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/dbtrace","name":"dbtrace","synopsis":"Package dbtrace counts database calls per request and logs the heavy ones.","isRedistributable":true}
