Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSQLComment ¶
func ParseSQLComment(query string) (CommentResult, CommentStatus)
ParseSQLComment extracts a W3C traceparent from a trailing sqlcommenter comment (e.g. /*traceparent='00-...-...-01'*/). It returns CommentOK with the parsed result on success, CommentInvalid if a traceparent key exists but the value is malformed, and CommentAbsent if no traceparent key is found.
func StripSQLComment ¶
StripSQLComment removes a trailing SQL block comment (such as a sqlcommenter comment) from the query. Non-trailing comments (e.g. optimizer hints) are preserved.
Types ¶
type CommentResult ¶
CommentResult holds the parsed traceparent from a sqlcommenter comment.
type CommentStatus ¶
type CommentStatus int
CommentStatus indicates the result of parsing a sqlcommenter traceparent.
const ( // CommentAbsent means no trailing comment or no traceparent key was found. CommentAbsent CommentStatus = iota // CommentInvalid means a traceparent key was found but the value is malformed. CommentInvalid // CommentOK means a valid traceparent was extracted. CommentOK )
type Correlator ¶
type Correlator struct {
// contains filtered or unexported fields
}
Correlator associates SQL spans with the most recently active HTTP/gRPC trace. It maintains a stack of active contexts so that concurrent requests are handled correctly: each SetActive pushes a context, ClearActive removes it, and Correlate returns the most recent non-expired entry.
func NewCorrelator ¶
func NewCorrelator(ttl time.Duration) *Correlator
func (*Correlator) ClearActive ¶
func (c *Correlator) ClearActive(traceID, spanID string)
ClearActive removes the entry matching the given traceID and spanID. Called when an HTTP or gRPC span completes.
func (*Correlator) Correlate ¶
func (c *Correlator) Correlate() (traceID, parentID string)
Correlate returns the trace and parent span ID for a SQL query. It returns the most recent non-expired entry from the stack. If no active trace is found within the TTL, new IDs are generated.
func (*Correlator) SetActive ¶
func (c *Correlator) SetActive(traceID, spanID string)
SetActive pushes a trace context onto the stack, typically called when an HTTP or gRPC span begins.
type DBProtocol ¶
type DBProtocol interface {
// Name returns the protocol name (e.g., "postgres", "mysql").
Name() string
// HandleConnection processes a single client connection, parsing the wire
// protocol and emitting QueryEvents through the callback.
HandleConnection(clientConn, serverConn RawConn, connID uint64, onQuery func(QueryEvent))
}
DBProtocol defines the interface for database wire protocol parsing. This allows future support for MySQL and other databases.
type PGProtocol ¶
type PGProtocol struct{}
PGProtocol implements DBProtocol for PostgreSQL wire protocol.
func (PGProtocol) HandleConnection ¶
func (PGProtocol) HandleConnection(clientConn, serverConn RawConn, connID uint64, onQuery func(QueryEvent))
func (PGProtocol) Name ¶
func (PGProtocol) Name() string
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}