Documentation
¶
Overview ¶
Package logs aggregates and formats log streams from multiple sources.
Index ¶
- func BestDetail(msgs []string) string
- func DedupeMessages(msgs []string) []string
- func FormatReport(w io.Writer, rep *AnalysisReport, topN int)
- func OwnerBadge(o Owner) string
- func StreamCFEntries(r io.Reader, fn func(CFExportEntry) error) (truncated bool, err error)
- type AnalysisReport
- type AnalyzeOptions
- type CFExportEntry
- type CFExportMetadata
- type CFExportSource
- type CFExportWorkers
- type CFExportWorkersEvent
- type CountItem
- type Diagnosis
- type ErrRecord
- type FlexTimestamp
- type IssueGroup
- type LogAggregator
- type LogSource
- type Owner
- type Signal
- type SourceWriter
- type StreamCollector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BestDetail ¶ added in v1.2.0
BestDetail extracts a concise single-line preview from deduplicated messages.
func DedupeMessages ¶ added in v1.2.0
DedupeMessages collapses Cloudflare's multi-fragment log bursts (e.g. request echo, bare "⨯", short stack, full stack) into distinct, non-redundant messages.
func FormatReport ¶ added in v1.2.0
func FormatReport(w io.Writer, rep *AnalysisReport, topN int)
FormatReport writes a concise, ownership-focused triage report to w.
func OwnerBadge ¶ added in v1.2.0
OwnerBadge returns a consistent ANSI-colored badge for terminal output.
func StreamCFEntries ¶ added in v1.2.0
StreamCFEntries streams a JSON array ([...]) or NDJSON stream of Cloudflare log objects in constant memory, tolerating a truncated tail cleanly.
Types ¶
type AnalysisReport ¶ added in v1.2.0
type AnalysisReport struct {
TotalRawEvents int `json:"totalRawEvents"`
DistinctRequests int `json:"distinctRequests"`
Truncated bool `json:"truncated,omitempty"`
ByOwner map[Owner]int `json:"byOwner"`
Groups []IssueGroup `json:"groups"`
TopPathStatus []CountItem `json:"topPathStatus"`
TopCountries []CountItem `json:"topCountries"`
ByMinute []CountItem `json:"byMinute"`
Records []ErrRecord `json:"records,omitempty"`
}
AnalysisReport summarizes a log stream or exported log file.
func AnalyzeFile ¶ added in v1.2.0
func AnalyzeFile(path string, opts AnalyzeOptions) (*AnalysisReport, error)
AnalyzeFile opens path and analyzes it in constant streaming memory.
func AnalyzeReader ¶ added in v1.2.0
func AnalyzeReader(r io.Reader, opts AnalyzeOptions) (*AnalysisReport, error)
AnalyzeReader streams JSON/NDJSON Cloudflare logs from r and returns an AnalysisReport.
type AnalyzeOptions ¶ added in v1.2.0
type AnalyzeOptions struct {
RouteFilter string
OwnerFilter Owner
AllLevels bool
RawNDJSONOut io.Writer
MergedNDJSONOut io.Writer
}
AnalyzeOptions configures streaming filtering and optional NDJSON output.
type CFExportEntry ¶ added in v1.2.0
type CFExportEntry struct {
Source CFExportSource `json:"source"`
Timestamp FlexTimestamp `json:"timestamp"`
Workers CFExportWorkers `json:"$workers"`
Metadata CFExportMetadata `json:"$metadata"`
}
CFExportEntry is the minimal shape of a Cloudflare Workers Observability event. Unknown fields are skipped during streaming decode.
type CFExportMetadata ¶ added in v1.2.0
type CFExportMetadata struct {
ID string `json:"id"`
RequestID string `json:"requestId"`
RayID string `json:"rayId"`
TraceID string `json:"traceId"`
Level string `json:"level"`
Error string `json:"error"`
Message string `json:"message"`
Trigger string `json:"trigger"`
Service string `json:"service"`
}
type CFExportSource ¶ added in v1.2.0
func (CFExportSource) MessageString ¶ added in v1.2.0
func (s CFExportSource) MessageString() string
MessageString converts Source.Message (string, array, or object) into a string.
type CFExportWorkers ¶ added in v1.2.0
type CFExportWorkers struct {
Event CFExportWorkersEvent `json:"event"`
ScriptName string `json:"scriptName"`
ScriptVersion struct {
ID string `json:"id"`
} `json:"scriptVersion"`
Outcome string `json:"outcome"`
WallTimeMs float64 `json:"wallTimeMs"`
CPUTimeMs float64 `json:"cpuTimeMs"`
}
func (CFExportWorkers) RequestIDCompat ¶ added in v1.2.0
func (w CFExportWorkers) RequestIDCompat() string
RequestIDCompat returns an empty string (Workers metadata requestId lives under $metadata.requestId in exports).
type CFExportWorkersEvent ¶ added in v1.2.0
type CFExportWorkersEvent struct {
Request struct {
URL string `json:"url"`
Path string `json:"path"`
Method string `json:"method"`
Headers map[string]string `json:"headers"`
CF struct {
Colo string `json:"colo"`
Country string `json:"country"`
ASN int `json:"asn"`
} `json:"cf"`
} `json:"request"`
Response struct {
Status int `json:"status"`
} `json:"response"`
}
type Diagnosis ¶ added in v1.2.0
type Diagnosis struct {
Owner Owner `json:"owner"`
Code string `json:"code"`
Summary string `json:"summary"`
Hint string `json:"hint"`
}
Diagnosis describes the classified fault owner, machine-readable code, and actionable hint.
type ErrRecord ¶ added in v1.2.0
type ErrRecord struct {
TS string `json:"ts"`
RequestID string `json:"requestId"`
RayID string `json:"rayId"`
Method string `json:"method,omitempty"`
URL string `json:"url"`
Path string `json:"path"`
Status int `json:"status"`
Outcome string `json:"outcome,omitempty"`
SegmentPrefetch string `json:"segmentPrefetch,omitempty"`
Colo string `json:"colo,omitempty"`
Country string `json:"country,omitempty"`
ASN int `json:"asn,omitempty"`
ScriptVer string `json:"scriptVersion,omitempty"`
Owner Owner `json:"owner"`
Code string `json:"code"`
Summary string `json:"summary"`
Hint string `json:"hint"`
Message string `json:"message"`
WallTimeMs float64 `json:"wallTimeMs,omitempty"`
CPUTimeMs float64 `json:"cpuTimeMs,omitempty"`
}
ErrRecord is the compact, merged, classified representation of one failing request.
type FlexTimestamp ¶ added in v1.2.0
type FlexTimestamp string
FlexTimestamp parses either an ISO-8601 string or a Unix-millisecond integer/float.
func (*FlexTimestamp) UnmarshalJSON ¶ added in v1.2.0
func (f *FlexTimestamp) UnmarshalJSON(data []byte) error
type IssueGroup ¶ added in v1.2.0
type IssueGroup struct {
Owner Owner `json:"owner"`
Code string `json:"code"`
Summary string `json:"summary"`
Hint string `json:"hint"`
Count int `json:"count"`
SampleRoutes []string `json:"sampleRoutes"`
ExtraRoutes int `json:"extraRoutes,omitempty"`
SampleDetail string `json:"sampleDetail,omitempty"`
}
IssueGroup aggregates distinct failing requests sharing the same (Owner, Code).
type LogAggregator ¶
LogAggregator formats and writes log lines from multiple sources.
func NewAggregator ¶
func NewAggregator(out io.Writer, appName string) *LogAggregator
NewAggregator returns a LogAggregator that writes formatted logs to out.
func (*LogAggregator) GetWriter ¶
func (a *LogAggregator) GetWriter(source LogSource) io.Writer
GetWriter returns an io.Writer that tags all writes with source.
func (*LogAggregator) WriteSource ¶
func (a *LogAggregator) WriteSource(source LogSource, p []byte) (n int, err error)
WriteSource formats and writes each non-empty line in p tagged with source.
type Owner ¶ added in v1.2.0
type Owner string
Owner identifies which layer is responsible for an error.
func ParseOwner ¶ added in v1.2.0
ParseOwner parses a user-supplied owner filter string. An empty string means "no filter" and returns "" with nil error.
type Signal ¶ added in v1.2.0
type Signal struct {
Method string
Path string
URL string
Status int
Outcome string
Headers map[string]string
Messages []string
Exceptions []string
}
Signal holds all available request/error signals used to classify a failure.
type SourceWriter ¶
type SourceWriter struct {
// contains filtered or unexported fields
}
SourceWriter implements io.Writer for a specific source.
type StreamCollector ¶ added in v1.2.0
type StreamCollector struct {
// contains filtered or unexported fields
}
StreamCollector merges multi-fragment Cloudflare log events by requestId and produces an AnalysisReport.
func NewStreamCollector ¶ added in v1.2.0
func NewStreamCollector(opts AnalyzeOptions) *StreamCollector
NewStreamCollector constructs a StreamCollector with the provided AnalyzeOptions.
func (*StreamCollector) Add ¶ added in v1.2.0
func (c *StreamCollector) Add(e CFExportEntry)
Add ingests a single CFExportEntry into the collector.
func (*StreamCollector) Finalize ¶ added in v1.2.0
func (c *StreamCollector) Finalize() *AnalysisReport
Finalize classifies all merged requests, applies filters, emits MergedNDJSONOut, and returns the report.
func (*StreamCollector) SetTruncated ¶ added in v1.2.0
func (c *StreamCollector) SetTruncated(t bool)
SetTruncated marks whether the underlying input stream terminated mid-JSON.