Documentation
¶
Overview ¶
Package trace captures request-lifecycle events (start, end, downstream calls, logs) into an in-memory ring buffer and fans them out to subscribers such as the dashboard. It is the data plane under /__nexus/events.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(bus *Bus, service, endpoint, transport string) gin.HandlerFunc
Middleware emits request.start and request.end events bracketing the handler chain, and stashes a *Span and the bus in gin.Context so Record() can attach downstream events to the same trace.
func NewTraceID ¶ added in v0.3.0
func NewTraceID() string
NewTraceID mints the next short, monotonic trace ID in the same format the request middleware uses. Exposed for code paths that emit events outside the HTTP request lifecycle (e.g. the cron scheduler) so trace IDs stay uniform across the dashboard.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is a bounded ring buffer + pub/sub. Slow subscribers drop events rather than block producers — the request path must never be held up by a stalled UI.
func BusFromCtx ¶
BusFromCtx returns the Bus from context, if the trace middleware stashed one.
type Event ¶
type Event struct {
ID int64 `json:"id"`
TraceID string `json:"traceId"`
Kind Kind `json:"kind"`
Service string `json:"service,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Transport string `json:"transport,omitempty"`
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
Status int `json:"status,omitempty"`
DurationMs int64 `json:"durationMs,omitempty"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp"`
Meta map[string]any `json:"meta,omitempty"`
}
type Kind ¶
type Kind string
const ( KindRequestStart Kind = "request.start" KindRequestEnd Kind = "request.end" // KindRequestOp is emitted by the metrics middleware AFTER the // handler returns, carrying the specific op name in Endpoint so // UI consumers can drive per-endpoint visualisations (packet // animations, per-op trace rows). request.start from the trace // middleware uses the HTTP path — too coarse to identify a // GraphQL operation; request.op fills that gap. KindRequestOp Kind = "request.op" KindDownstream Kind = "downstream" KindLog Kind = "log" )