Documentation
¶
Overview ¶
Package apptrace keeps a bounded, in-memory trace of every AWS API call that passes through the router, plus child spans for cross-service deliveries (SNS to SQS, EventBridge targets, ...) linked to the request that triggered them.
Index ¶
- Constants
- func Middleware(t *Tracer) echo.MiddlewareFunc
- func WithSpan(ctx context.Context, s *Span) context.Context
- type ChildInfo
- type Config
- type Detail
- type Filter
- type ListResult
- type Span
- type Tracer
- func (t *Tracer) Clear()
- func (t *Tracer) Config() Config
- func (t *Tracer) DetailEnabled() bool
- func (t *Tracer) Enabled() bool
- func (t *Tracer) Get(id string) (Span, bool)
- func (t *Tracer) List(f Filter) ListResult
- func (t *Tracer) Record(s *Span)
- func (t *Tracer) Recorded() uint64
- func (t *Tracer) SetDetail(v bool)
- func (t *Tracer) SetEnabled(v bool)
- func (t *Tracer) Trace(traceID string) []Span
Constants ¶
const ( KindRequest = "request" KindInternal = "internal" )
Span kinds.
const ( DefaultCapacity = 2000 DefaultMaxBody = 4096 )
Defaults for Config fields left zero.
const Redacted = "[REDACTED]"
Redacted replaces every secret value.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(t *Tracer) echo.MiddlewareFunc
Middleware traces every API request. Metadata is always cheap; headers and bodies are captured only while Tracer.DetailEnabled.
Types ¶
type ChildInfo ¶
type ChildInfo struct {
Service string
Operation string
Resource string
Region string
Account string
}
ChildInfo describes an internal delivery to trace.
type Config ¶
type Config struct {
// Capacity is the ring size in spans.
Capacity int
// MaxBody caps each captured body in bytes.
MaxBody int
// Enabled turns metadata recording on.
Enabled bool
// Detail additionally captures redacted headers and bodies.
Detail bool
}
Config configures a Tracer.
type Detail ¶
type Detail struct {
RequestHeaders map[string]string `json:"requestHeaders,omitempty"`
ResponseHeaders map[string]string `json:"responseHeaders,omitempty"`
Query string `json:"query,omitempty"`
RequestBody string `json:"requestBody,omitempty"`
ResponseBody string `json:"responseBody,omitempty"`
RequestTrunc bool `json:"requestBodyTruncated,omitempty"`
ResponseTrunc bool `json:"responseBodyTruncated,omitempty"`
}
Detail is the opt-in capture of headers and truncated, redacted bodies.
type Filter ¶
type Filter struct {
Service string
Operation string
Region string
Account string
Principal string
ErrorCode string
TraceID string
ParentID string
Kind string
Query string
AfterSeq uint64
Limit int
Offset int
MinStatus int
MaxStatus int
ErrorsOnly bool
}
Filter selects spans for Tracer.List. Zero fields match everything.
type ListResult ¶
type ListResult struct {
Items []Span `json:"items"`
Total int `json:"total"`
Capacity int `json:"capacity"`
Recorded uint64 `json:"recorded"`
}
ListResult is a page of spans, newest first.
type Span ¶
type Span struct {
Start time.Time `json:"time"`
Detail *Detail `json:"detail,omitempty"`
ID string `json:"id"`
TraceID string `json:"traceId"`
ParentID string `json:"parentId,omitempty"`
Kind string `json:"kind"`
Service string `json:"service"`
Operation string `json:"operation"`
Resource string `json:"resource,omitempty"`
Region string `json:"region,omitempty"`
Account string `json:"account,omitempty"`
Principal string `json:"principal,omitempty"`
AccessKeyID string `json:"accessKeyId,omitempty"`
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
LatencyMs float64 `json:"latencyMs"`
RequestBytes int64 `json:"requestBytes"`
ResponseBytes int64 `json:"responseBytes"`
Seq uint64 `json:"seq"`
Status int `json:"status"`
HasDetail bool `json:"hasDetail,omitempty"`
// contains filtered or unexported fields
}
Span is one recorded API call or internal delivery. It is immutable once handed to Tracer.Record.
func FromContext ¶
FromContext returns the current span, or nil when the request is not traced.
func StartChild ¶
StartChild opens a child span under the span in ctx. It returns ctx unchanged and a nil span when ctx is untraced; Span.Finish is nil-safe.
func (*Span) SetOperation ¶
SetOperation records the service, operation and resource the service layer resolved for this request. Safe on a nil span.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer is a fixed-capacity, lock-free ring of committed spans.
func (*Tracer) DetailEnabled ¶
DetailEnabled reports whether headers and bodies are captured.
func (*Tracer) List ¶
func (t *Tracer) List(f Filter) ListResult
List returns spans matching f, newest first, without their Detail.
func (*Tracer) Recorded ¶
Recorded is the total number of spans ever committed, including evicted ones.
func (*Tracer) SetEnabled ¶
SetEnabled toggles recording at runtime.