trace

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package trace reads distributed-tracing exports and reduces them to the few facts GraphLume can line up against the static graph: which endpoints were really called, which functions really ran, which tables were really touched, and how long each took.

What this is, and what it deliberately is not

It is a READER, not a tracing system.

It does not sample. Sampling is a decision the producer already made, before these bytes existed; re-sampling here would silently change the denominator under every count this package reports, and a call rate computed from a sample the caller did not choose is worse than no call rate.

It does not talk to a collector, an agent, a Jaeger query API or any other network endpoint. The only input is a byte slice the caller already holds. That boundary is what makes the whole package testable against raw exporter output, and it is why nothing here can leak a repository's trace data outward.

It does not correlate. Nothing in this file knows what a symbol, an endpoint or a table row in the index looks like, and it never will. A CodeHint is the raw material for correlation — a function name, a route template, a file and line — handed back verbatim for the caller to match against the graph. Keeping the matching rules out of here is deliberate: those rules differ per language and per instrumentation library, they change often, and burying them in a parser would make both halves untestable.

It does not retain the export. Spans carry arbitrary user attributes — SQL text with embedded credentials, URLs with bearer tokens, request bodies. Only a small allow-list of keys survives parsing; see [allowedAttributes].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(src []byte, maxBytes int64) (spans []Span, format Format, err error)

Parse reads spans from an OTLP/JSON or Jaeger-UI JSON export. Returns the format it used. maxBytes <= 0 means the package default.

Every bound is reported as an error naming the limit. The span list is never silently truncated: a caller that asked "which endpoints are never called" and got a quietly shortened span set would conclude that live endpoints are dead, which is the single most damaging wrong answer this package could give.

Types

type CodeHint

type CodeHint struct {
	// Function is from code.function / code.function.name.
	Function string
	// Namespace is from code.namespace (a class or package).
	Namespace string
	// File and Line are from code.filepath / code.lineno.
	File string
	Line int
	// Route is the HTTP route template from http.route (NOT http.target,
	// which carries real path parameters and would explode the cardinality).
	Route  string
	Method string // http.method / http.request.method
	// DBTable is from db.sql.table / db.collection.name.
	DBTable string
	// DBOperation is from db.operation / db.operation.name.
	DBOperation string
}

CodeHint is what this span says about the code that produced it.

func (CodeHint) Empty

func (h CodeHint) Empty() bool

Empty reports whether the hint says nothing about code. Callers use it to skip operations that cannot be matched to the graph at all, rather than reporting them as "unmatched code".

type Format

type Format string

Format identifies which exporter produced a file.

const (
	FormatOTLPJSON Format = "otlp-json"
	FormatJaeger   Format = "jaeger"
	FormatUnknown  Format = ""
)

func Detect

func Detect(src []byte) Format

Detect sniffs the format from the first bytes of a document.

type Operation

type Operation struct {
	Name    string
	Service string
	Calls   int
	Errors  int
	// P50Nanos and P95Nanos are computed from the observed durations. They are
	// exact percentiles over the spans present, not an estimate.
	P50Nanos int64
	P95Nanos int64
	Hint     CodeHint
}

Operation is one span name aggregated across traces.

type Span

type Span struct {
	TraceID    string
	SpanID     string
	ParentID   string
	Name       string
	Service    string
	Kind       string // server | client | internal | producer | consumer | ""
	StartNanos int64
	EndNanos   int64
	// Status is "ok" | "error" | "" (unset).
	Status string
	// Attributes holds only the KEYS GraphLume correlates on; see CodeHint.
	Attributes map[string]string
}

Span is one operation in a distributed trace, reduced to what GraphLume can correlate with code.

func (Span) DurationNanos

func (s Span) DurationNanos() int64

DurationNanos is End-Start, or 0 when either is missing.

A negative difference is also reported as 0 rather than as a negative duration. It happens for real — a span whose start and end were stamped on two machines with skewed clocks — and letting it through would drag a percentile below zero, which is a latency no reader can act on.

func (Span) Hint

func (s Span) Hint() CodeHint

Hint extracts the correlation hints from a span's attributes.

type Summary

type Summary struct {
	Traces     int
	Spans      int
	Services   []string // sorted
	Errors     int
	Operations []Operation // sorted by Calls descending, then Name
}

Summary aggregates spans for reporting.

func Summarise

func Summarise(spans []Span) Summary

Summarise aggregates a span set.

Grouping is by (Name, Service), not by Name alone. Two services routinely name an operation `GET /health`, and merging them would report one latency distribution for two unrelated pieces of code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL