Documentation
¶
Overview ¶
Package traceimport infers a motel topology from recorded trace data. The pipeline parses spans, reconstructs trace trees, computes per-operation statistics, and serialises the result as a topology YAML file.
YAML serialisation of inferred config using the map-based form matching the synth DSL Produces output compatible with synth.LoadConfig for round-trip validation
Recording export: serialise reconstructed trace trees to a replay sidecar.
Normalised span type and format-specific parsers for trace inference Handles stdouttrace, OTLP protobuf JSON, and Jaeger JSON formats
Per-operation statistical accumulators for duration, error rate, and call patterns Analyses trace trees to collect distributions needed for config generation
Trace tree reconstruction from flat span lists Groups spans by trace ID and links children to parents via span IDs
Index ¶
- func FormatErrorRate(errors, total int) string
- func MarshalConfig(collector *StatsCollector, serviceAttrs map[string]map[string]string, ...) ([]byte, error)
- func WriteRecording(trees []*TraceTree, w io.Writer) error
- type CallStats
- type CallStyleVote
- type Format
- type OpStats
- type Options
- type Result
- type ServiceStats
- type Span
- type SpanNode
- type StatsCollector
- type TraceTree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatErrorRate ¶
FormatErrorRate returns a percentage string like "0.10%" or empty if zero.
Types ¶
type CallStats ¶
CallStats separates how often a call happens from how many times it happens.
Count is the number of parent invocations that made the call at least once — the probability numerator. Occurrences is the total number of call occurrences across those invocations, so the typical per-invocation repetition (the emitted count:) is round(Occurrences / Count). Keeping these apart prevents a call made several times within one invocation from being mistaken for a call made across several invocations.
type CallStyleVote ¶
CallStyleVote tracks parallel vs sequential votes across traces.
type Format ¶
type Format string
Format identifies the input trace format.
const ( FormatAuto Format = "auto" // Detects the format from the input. FormatStdouttrace Format = "stdouttrace" // Line-delimited JSON from the OTel stdout exporter. FormatOTLP Format = "otlp" // OTLP protobuf JSON. FormatJaeger Format = "jaeger" // Jaeger JSON export format (also used by Grafana Tempo). FormatMetaSummary Format = "meta-summary" // Meta ATC 2023 parent-data.csv summary rows. )
Supported trace input formats.
type OpStats ¶
type OpStats struct {
DurationCount int
DurationMean float64
DurationM2 float64
ErrorCount int
TotalCount int
Calls map[string]*CallStats // key: "targetService.targetOp"
}
OpStats accumulates statistics for a single (service, operation) pair.
type Options ¶
type Options struct {
Format Format
MinTraces int
Warnings io.Writer // defaults to os.Stderr
MetaProfile string
MetaIncludeEmpty bool
// RecordTo, when non-nil, receives a newline-delimited replay recording of
// the source traces alongside the inferred topology. Not supported for
// Meta summary imports, which carry no per-trace span data.
RecordTo io.Writer
}
Options controls import behaviour.
type Result ¶ added in v0.9.2
type Result struct {
// YAML is the inferred synth topology.
YAML []byte
// TraceCount is the number of source traces. For Meta summary imports it is
// the total weighted parent-sample count rather than a literal trace count.
TraceCount int
// SpanCount is the number of source spans. For Meta summary imports it is an
// estimate derived from the weighted call counts rather than a literal span
// count.
SpanCount int
}
Result contains the inferred topology and source counts from an import.
For span-based imports (OTLP, stdouttrace, auto) the counts are literal. For Meta summary imports they are weighted estimates rather than observed values; see the field comments.
type ServiceStats ¶
type ServiceStats struct {
Ops map[string]*OpStats // operation name -> stats
CallStyles map[string]*CallStyleVote // operation name -> voting
}
ServiceStats holds per-operation stats and call style votes for one service.
type Span ¶
type Span struct {
TraceID string
SpanID string
ParentID string // empty for root spans
Service string
Operation string
StartTime time.Time
EndTime time.Time
IsError bool
Attributes map[string]string
}
Span is the format-independent representation of a trace span.
func ParseSpans ¶
ParseSpans reads spans from the given reader in the specified format. FormatAuto inspects the first JSON object to determine the format. Whole-document JSON inputs are limited to 256 MB to prevent OOM on large trace exports. Explicit line-delimited stdouttrace inputs are scanned incrementally.
type StatsCollector ¶
type StatsCollector struct {
Services map[string]*ServiceStats // service name -> stats
}
StatsCollector accumulates statistics across all traces.
func NewStatsCollector ¶
func NewStatsCollector() *StatsCollector
NewStatsCollector creates an empty collector.
func (*StatsCollector) CollectFromTrees ¶
func (c *StatsCollector) CollectFromTrees(trees []*TraceTree)
CollectFromTrees walks all trace trees, accumulating per-operation statistics.