memorytelemetry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package memorytelemetry provides an in-process telemetry.TraceDriver, telemetry.MetricDriver, and telemetry.LogDriver for tests, local development, and applications that want trace IDs in logs and responses without a backend.

The driver generates W3C trace and span IDs, propagates them with the traceparent and tracestate headers, keeps a bounded ring of finished spans and another of log records, and aggregates metrics in memory. It exports nothing. Driver.Spans, Driver.Logs, and Driver.Metrics return detached eager collection snapshots. Filtering and grouping operate on those snapshots, not live rings: later recordings, eviction, and Reset do not change them. The snapshot methods copy owned nested containers before wrapping; collection wrappers themselves add no ownership. Records reach the ring through telemetry.Telemetry.Handler, which also adds trace_id and span_id to the wrapped logger's output; a Log carries the span identity of its context, so a record joins its span by span ID. Recorders returned by Driver.StartSpan expose the actual selected parent through telemetry.SpanRecorder.Parent, including in IDs-only mode. Inactive recorders and roots return zero. Passive capture stores the backend parent reported by the facade; it does not reconstruct parentage from a context slot.

Every Log carries a Log.Seq, increasing from 1 and never reused, even across Driver.Reset. A follower tails the log ring without polling by waiting on Driver.LogsChanged and reading Driver.LogsAfter with the last Seq it handled; a first Seq above last+1 tells it records were dropped.

Driver.MCPTools publishes typed, SDK-independent diagnostic tools for explicit composition. Log calls support bounded cursor polling: omitted cursor returns recent history, tail returns an immediate empty anchor, and continuation calls wait at most 25 seconds. Each response reports lost records and a new opaque cursor. Reset changes the capture generation even on an empty ring; a stale cursor returns instance_changed with a fresh tail.

tools := driver.MCPTools("memory")
for _, tool := range tools {
	if err := tool.Err(); err != nil {
		return err
	}
}

Set Builder.MaxSpans to 0 to generate IDs only and keep no spans, and Builder.MaxLogs to 0 to keep no log records. Each ring holds 1000 entries by default.

driver := memorytelemetry.New(func(store *memorytelemetry.Builder) {
	store.MaxSpans(100)
	store.MaxLogs(500)
})
app := application.New(func(app *application.Builder) {
	app.Telemetry(telemetry.New(driver))
})

New applies callbacks directly once, synchronously in order on one fresh Builder. Capacity settings return that same draft and replace earlier values. Publication copies the root, so retained drafts cannot resize a store. Omitted callbacks and nil/empty expanded slices keep defaults; supplied nil entries and callback panics propagate. telemetrytest.New forwards this construction contract once, separately from its suite options.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrAmbiguousTrace = mcp.ToolFailure("ambiguous_trace", "The prefix matches more than one trace; use a longer prefix", nil)

ErrAmbiguousTrace is the safe MCP failure the trace operation returns when a trace ID prefix matches more than one recorded trace. It lists no candidates; retry with a longer prefix.

Example:

failure, ok := mcp.ToolFailureInfo(memorytelemetry.ErrAmbiguousTrace)
if ok { fmt.Println(failure.Code) }
View Source
var ErrTraceNotFound = mcp.ToolFailure("trace_not_found", "No recorded trace has that ID; it may have been evicted", nil)

ErrTraceNotFound is the safe MCP failure the trace operation returns when no recorded trace has the requested ID or ID prefix. The trace may have been evicted from the ring.

Example:

failure, ok := mcp.ToolFailureInfo(memorytelemetry.ErrTraceNotFound)
if ok { fmt.Println(failure.Code) }

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder configures recording capacities before New publishes a driver. Settings replace previous values. New copies the completed root, so a retained draft cannot resize a running store.

store := memorytelemetry.New(func(store *memorytelemetry.Builder) {
	store.MaxSpans(500)
})

func (*Builder) MaxLogs

func (store *Builder) MaxLogs(maxLogs int) *Builder

MaxLogs replaces log-record capacity and returns the same draft. The default is 1000; zero or negative keeps no logs. At capacity the oldest record is dropped. This does not change span or series capacity.

store := memorytelemetry.New(func(store *memorytelemetry.Builder) {
	store.MaxLogs(500)
})

func (*Builder) MaxSeries

func (store *Builder) MaxSeries(maxSeries int) *Builder

MaxSeries replaces per-instrument label-combination capacity and returns the same draft. The default is 1000; zero or negative keeps no metrics. New combinations beyond the capacity are dropped, not existing series.

store := memorytelemetry.New(func(store *memorytelemetry.Builder) {
	store.MaxSeries(50)
})

func (*Builder) MaxSpans

func (store *Builder) MaxSpans(maxSpans int) *Builder

MaxSpans replaces finished-span capacity and returns the same draft. The default is 1000; zero or negative retains no spans but still generates and propagates IDs. At capacity the oldest finished span is dropped.

store := memorytelemetry.New(func(store *memorytelemetry.Builder) {
	store.MaxSpans(500)
})

type BuilderFunc

type BuilderFunc = func(*Builder)

BuilderFunc configures one memory-driver construction draft. Settings are copied at publication, so retaining the callback's draft cannot resize a store.

var configure memorytelemetry.BuilderFunc = func(store *memorytelemetry.Builder) {
	store.MaxSpans(100).MaxLogs(100).MaxSeries(50)
}
store := memorytelemetry.New(configure)
fmt.Println(len(store.Spans())) // Construction records nothing.

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver implements telemetry.TraceDriver, telemetry.MetricDriver, and telemetry.LogDriver in process memory. It is safe for concurrent use.

It is also a telemetry.Observer: attached with telemetry.Telemetry.Observe it keeps a passive copy of what another backend, such as OpenTelemetry, receives, with the same trace and span IDs, in the same rings and series as when it is the driver. Where the telemetry has no trace or metric driver of its own, the attached driver fills in for it (the first attached wins) and then records each span and measurement once. Start the driver yourself: Observe does not, and a driver that is not started discards everything.

Span and trace IDs come from the runtime's randomly seeded generator, which is cheap and sufficient for uniqueness; they are not secrets. A span inherits the sampled flag of its parent and is sampled when it has none.

Example:

store := memorytelemetry.New()
if err := store.Start(ctx, telemetry.Setup{}); err != nil {
	return err
}
tools := store.MCPTools("memory")
_ = tools
Example

ExampleDriver records a span and reads it back.

package main

import (
	"context"
	"fmt"

	"arkoren.dev/core/service/telemetry"
	"arkoren.dev/core/service/telemetry/memorytelemetry"
)

func main() {
	driver := memorytelemetry.New()
	facade := telemetry.New(driver)

	if err := facade.Start(context.Background(), telemetry.Setup{}); err != nil {
		fmt.Println(err)

		return
	}

	defer func() {
		// The concrete memory driver never fails to stop.
		_ = facade.Stop(context.Background())
	}()

	_, span := facade.Tracer("example").Start(context.Background(), "greeting send")
	span.End()

	spans := driver.Spans()
	fmt.Println(len(spans), spans[0].Name)
}
Output:
1 greeting send

func New

func New(configure ...BuilderFunc) *Driver

New returns a Driver with default recording capacities and applies callbacks directly once, synchronously in order on one fresh draft. Supplied nil callbacks and callback panics propagate; omitted callbacks and expanded nil/empty slices make no edits. Publication copies the completed settings. It performs no I/O; call Start before recording.

store := memorytelemetry.New(func(store *memorytelemetry.Builder) {
	store.MaxSpans(500)
})

func (*Driver) Enabled

func (driver *Driver) Enabled(context.Context, slog.Level) bool

Enabled reports whether Export keeps a record: the driver is started and the Builder.MaxLogs capacity is positive. The driver keeps every level.

if store.Enabled(ctx, slog.LevelInfo) {
	fmt.Println("capture accepts this record")
}

func (*Driver) Export

func (driver *Driver) Export(ctx context.Context, record slog.Record) error

Export stores record in the ring of logs, dropping the oldest record when it is full, and never fails. It gives the record the next Log.Seq and wakes the channels returned by Driver.LogsChanged. It resolves LogValuer and text-formatting callbacks before taking the driver's mutex. These callbacks may block or reenter the driver; Export cannot cancel them. It discards the record, and assigns no Seq, when the driver is not started or the Builder.MaxLogs capacity is not positive. The record is copied, so the caller may reuse it. Stop synchronizes with the final commit, so an export whose callbacks finish after Stop cannot assign a Seq, append a log, or notify followers.

record := slog.NewRecord(time.Time{}, slog.LevelInfo, "started", 0)
if err := driver.Export(ctx, record); err != nil {
	return err
}

func (*Driver) Extract

func (driver *Driver) Extract(ctx context.Context, carrier telemetry.Carrier) (context.Context, telemetry.SpanContext)

Extract reads traceparent and tracestate. Malformed headers yield the zero span context. This raw operation does not authenticate the sender; the caller applies trust.

ctx, parent := store.Extract(ctx, carrier)
if parent.IsValid() {
	fmt.Println(parent.TraceID.String())
}
_ = ctx

func (*Driver) Inject

func (driver *Driver) Inject(ctx context.Context, carrier telemetry.Carrier)

Inject writes traceparent, and tracestate when present, for the current span of ctx. With a started store and a context carrying a span, propagate into an owned map:

carrier := telemetry.MapCarrier{}
store.Inject(ctx, carrier)
fmt.Println(carrier.Get("traceparent"))

func (*Driver) Instrument

func (driver *Driver) Instrument(spec telemetry.InstrumentSpec) (telemetry.InstrumentRecorder, error)

Instrument registers the instrument, or returns the recorder of an already registered one with the same scope and name. With store already started, raw recordings supply one value per key:

recorder, err := store.Instrument(telemetry.InstrumentSpec{
	Name: "requests", Kind: telemetry.CounterKind, Keys: []string{"result"},
})
if err != nil {
	return err
}
recorder.Record(ctx, 1, []string{"hit"})

func (*Driver) Logged

func (driver *Driver) Logged(ctx context.Context, record slog.Record)

Logged stores record in the ring of logs exactly as Driver.Export does, with ctx supplying Log.Context and the next Log.Seq. The driver keeps every level of what it is handed and discards records when it is not started or the Builder.MaxLogs capacity is not positive. With capture already started, forwarded records retain their original context:

record := slog.NewRecord(time.Time{}, slog.LevelInfo, "operation completed", 0)
capture.Logged(ctx, record)
fmt.Println(len(capture.Logs()))

func (*Driver) Logs

func (driver *Driver) Logs() collection.Slice[Log]

Logs returns a snapshot of the exported log records, oldest first. Mutating it does not affect the driver. It equals LogsAfter(0). This eager collection is not a live query and survives ring eviction or Reset; the snapshot copies, not its collection wrapper, provide ownership.

warnings := driver.Logs().Filter(func(_ int, entry memorytelemetry.Log) bool {
	return entry.Level >= slog.LevelWarn
})
for _, entry := range warnings {
	fmt.Println(entry.Level, entry.Message)
}

func (*Driver) LogsAfter

func (driver *Driver) LogsAfter(seq uint64) collection.Slice[Log]

LogsAfter returns a deep copy of the records still in the ring whose Log.Seq is greater than seq, oldest first. It returns nil when there are none, including when the Builder.MaxLogs capacity is not positive. Mutating the result does not affect the driver. The collection is eager: later exports and Reset cannot change its records or copied attributes. The wrapper itself performs no additional copying.

A follower passes the Seq of the last record it handled. Seq values are consecutive, so the follower detects dropped records when the first returned Seq is greater than seq+1; the number dropped is first.Seq-seq-1. With seq 0 the first returned Seq above 1 means records were evicted or discarded by Driver.Reset before the call.

last := uint64(0)
for _, entry := range driver.LogsAfter(last) {
	last = entry.Seq
	fmt.Println(entry.Message)
}

func (*Driver) LogsChanged

func (driver *Driver) LogsChanged() <-chan struct{}

LogsChanged returns a channel that is closed the next time a record is exported or Driver.Reset runs, whichever comes first. A closed channel stays closed; call LogsChanged again for the next change. It is how a follower waits without polling.

To miss no record, take the channel before reading: a record exported between the two calls then closes the channel the follower already holds. With a nonpositive Builder.MaxLogs capacity nothing is ever exported, so the channel closes only at Reset.

for {
	changed := driver.LogsChanged()
	for _, entry := range driver.LogsAfter(last) {
		last = entry.Seq
	}
	select {
	case <-changed:
	case <-ctx.Done():
		return
	}
}

func (*Driver) MCPTools

func (driver *Driver) MCPTools(prefix string) []mcp.Tool

MCPTools publishes SDK-independent read-only diagnostics over retained traces, trace trees, logs, and metrics. Empty prefix produces unqualified names in the telemetry CLI group; a nonempty prefix produces prefix.traces, prefix.trace, prefix.logs, and prefix.metrics in that prefix's CLI group. Native roles identify each diagnostic operation independently of its name. Applications compose these declarations explicitly with other owners' tools.

The declarations own no resources and do not start the driver. Retention follows Builder.MaxSpans, Builder.MaxLogs, and Builder.MaxSeries. Logs support history snapshots, immediate tail anchoring, and bounded continuation polling. Reset invalidates the store generation and returns a fresh tail with instance_changed. Malformed/foreign/future cursors return safe failures. Availability and outer transport authentication remain composition concerns.

Example:

store := memorytelemetry.New()
tools := store.MCPTools("memory")
for _, tool := range tools {
	if err := tool.Err(); err != nil { return err }
}

func (*Driver) Measured

func (driver *Driver) Measured(spec telemetry.InstrumentSpec, value float64, values []string)

Measured aggregates one recording into the series of the instrument spec describes, creating the instrument on first use, exactly as a recorder from Driver.Instrument would. Recordings that would exceed the Builder.MaxSeries capacity are dropped, and nothing is kept when the driver is not started. With capture already started, raw observation supplies a complete schema and one label value per key; capture owns independent schema and value containers.

spec := telemetry.InstrumentSpec{Name: "requests", Kind: telemetry.CounterKind, Keys: []string{"result"}}
capture.Measured(spec, 1, []string{"hit"})
fmt.Println(len(capture.Metrics()))

func (*Driver) Metrics

func (driver *Driver) Metrics() collection.Slice[Metric]

Metrics returns a snapshot of every instrument in creation order. Mutating it does not affect the driver. Existing instruments remain in the result after Reset, with empty Points until another recording; unregistered names are not synthesized. The eager snapshot copies keys, points, and label values before wrapping them. Later recordings and Reset do not change it; it is not a live query.

byScope := store.Metrics().GroupBy(func(_ int, metric memorytelemetry.Metric) string {
	return metric.Scope
})
for _, metric := range byScope["example.com/billing"] {
	fmt.Println(metric.Scope, metric.Name, len(metric.Points))
}

func (*Driver) Reset

func (driver *Driver) Reset()

Reset discards recorded spans, logs, and metric values. Instruments stay registered, so live instruments keep recording. It wakes Driver.LogsChanged waiters but does not restart Log.Seq, so a log follower sees a gap, not a repeat, after a Reset. MCP continuation cursors instead observe a changed store generation and receive an empty instance_changed result anchored at the fresh tail.

Example:

store := memorytelemetry.New()
store.Reset()
if len(store.Logs()) != 0 {
	panic("capture was not cleared")
}

func (*Driver) Resource

func (driver *Driver) Resource() telemetry.Resource

Resource returns the resource the driver was started with. Its attribute container is copied; editing that container does not change future snapshots. Before Start the resource is the zero value.

store := memorytelemetry.New()
if err := store.Start(ctx, telemetry.Setup{Resource: telemetry.Resource{Service: "billing"}}); err != nil {
	return err
}
fmt.Println(store.Resource().Service) // billing
if err := store.Stop(ctx); err != nil {
	return err
}

func (*Driver) SpanEnded

func (driver *Driver) SpanEnded(span telemetry.FinishedSpan)

SpanEnded stores span in the ring of finished spans, dropping the oldest when it is full. It is how the driver keeps a passive copy of the spans of another telemetry backend, with that backend's IDs; see Driver and telemetry.Telemetry.Observe. The span is copied. Nothing is stored when the driver is not started or the Builder.MaxSpans capacity is not positive. With capture already started, a forwarding observer may submit a completed snapshot; ordinary facade users attach capture through Telemetry.Observe.

capture.SpanEnded(telemetry.FinishedSpan{
	Name: "cache get", Kind: telemetry.Internal, Status: telemetry.Unset,
	Context: telemetry.SpanContext{TraceID: telemetry.TraceID{1}, SpanID: telemetry.SpanID{2}},
})
fmt.Println(len(capture.Spans()))

func (*Driver) Spans

func (driver *Driver) Spans() collection.Slice[Span]

Spans returns a snapshot of the finished spans, oldest first. Mutating it does not affect the driver. Only finished, retained spans appear; ongoing and evicted spans are absent. The eager snapshot remains stable across ring eviction and Reset. The collection wrapper adds operations; cloning here provides its ownership.

failed := store.Spans().Filter(func(_ int, span memorytelemetry.Span) bool {
	return span.Status == telemetry.Error
})
for _, span := range failed {
	fmt.Println(span.Name, span.Parent.IsValid(), span.End.Sub(span.Start))
}

func (*Driver) Start

func (driver *Driver) Start(_ context.Context, setup telemetry.Setup) error

Start begins recording. It returns an error wrapping telemetry.ErrStarted on a second call and telemetry.ErrStopped after Stop.

store := memorytelemetry.New()
if err := store.Start(ctx, telemetry.Setup{Resource: telemetry.Resource{Service: "billing"}}); err != nil {
	return err
}
if err := store.Stop(ctx); err != nil {
	return err
}

func (*Driver) StartSpan

func (driver *Driver) StartSpan(ctx context.Context, start telemetry.SpanStart) (context.Context, telemetry.SpanRecorder)

StartSpan starts a span as a child of the current span of ctx. It returns ctx unchanged. The span records attributes and events only when the capacity set by Builder.MaxSpans is positive. With store already started, the raw recorder exposes selected parent metadata:

_, recorder := store.StartSpan(ctx, telemetry.SpanStart{Name: "cache get", Kind: telemetry.Client})
fmt.Println(recorder.Context().IsValid(), recorder.Parent().IsValid())
recorder.End()

func (*Driver) Stop

func (driver *Driver) Stop(context.Context) error

Stop stops recording. Recorded data stays readable through Driver.Spans, Driver.Logs, and Driver.Metrics. It is idempotent and never fails. It synchronizes with aggregate and ring commits, but does not wait for caller LogValuer or error-formatting callbacks. Pending recordings are dropped after their callbacks return. Even an expired context releases the recording state; this in-process driver owns no external resources to flush.

if err := driver.Stop(ctx); err != nil {
	return err
}
logs := driver.Logs() // Still readable; no pending export can append now.
_ = logs

type Event

type Event = telemetry.SpanEvent

Event is a timestamped annotation on a Span: an alias of telemetry.SpanEvent. The alias lets capture readers consume the contract's event shape unchanged.

event := memorytelemetry.Event{Name: "retry", Attrs: []telemetry.Attr{telemetry.Int("attempt", 2)}}
fmt.Println(event.Name, event.Attrs[0].AsInt64())

type Log

type Log struct {
	// Seq is the position of the record in the driver's stream of exported
	// records: assigned by [Driver.Export], 1 for the first record and
	// strictly increasing by one for each later one, and never reused. It
	// does not restart at [Driver.Reset], so a follower that remembers the
	// last Seq it saw never sees it go backwards. A gap between two
	// consecutive Seq values a reader sees means the ring evicted records
	// in between; see [Driver.LogsAfter].
	//
	//	lastSeq := uint64(0)
	//	for _, entry := range store.LogsAfter(lastSeq) {
	//		lastSeq = entry.Seq
	//	}
	//	fmt.Println(lastSeq)
	Seq uint64

	// Time is the time of the record. It is zero when the logger set none.
	// It is the emitted timestamp, not the time a snapshot was retrieved.
	//
	//	for _, entry := range store.Logs() {
	//		fmt.Println(entry.Time.UTC().Format(time.RFC3339Nano))
	//	}
	Time time.Time

	// Level is the severity of the record.
	// It retains slog's numeric level, including application-defined levels.
	//
	//	for _, entry := range store.Logs() {
	//		if entry.Level >= slog.LevelWarn {
	//			fmt.Println(entry.Message)
	//		}
	//	}
	Level slog.Level

	// Message is the log message.
	// It is application-supplied text, so producers must exclude secrets.
	//
	//	for _, entry := range store.Logs() {
	//		fmt.Println(entry.Message)
	//	}
	Message string

	// Context is the identity of the span in the context the record was
	// logged with, so a record joins its span by Context.SpanID. It is the
	// zero value, and not valid, when the context held no span.
	//
	//	for _, entry := range store.Logs() {
	//		if entry.Context.IsValid() {
	//			fmt.Println(entry.Context.TraceID.String())
	//		}
	//	}
	Context telemetry.SpanContext

	// Attrs are the record attributes in logging order, including those added
	// by WithAttrs and WithGroup. Attributes inside groups are flattened with
	// dotted keys, such as "http.method". Strings, integers, floats, and
	// booleans keep their type; every other value, such as a time, a duration,
	// or an error, is kept in its text form. The correlation attributes
	// trace_id and span_id are not included; use Context.
	//
	//	for _, entry := range store.Logs() {
	//		for _, attr := range entry.Attrs {
	//			fmt.Println(attr.Key(), attr.Value())
	//		}
	//	}
	Attrs []telemetry.Attr
}

Log is the snapshot of a log record exported to the driver. Obtain detached snapshots from Driver.Logs or Driver.LogsAfter; their order is export order, and Seq provides a continuation position across ring eviction.

for _, entry := range store.LogsAfter(0) {
	fmt.Println(entry.Seq, entry.Level, entry.Message)
}

type Metric

type Metric struct {
	// Scope is the instrumentation scope of the meter.
	// Names may repeat in distinct scopes without sharing an aggregate.
	//
	//	for _, metric := range store.Metrics() {
	//		fmt.Println(metric.Scope, metric.Name)
	//	}
	Scope string

	// Name is the instrument name.
	// It is the declared portable name rather than a backend-translated spelling.
	//
	//	for _, metric := range store.Metrics() {
	//		fmt.Println(metric.Name)
	//	}
	Name string

	// Description is the help text.
	// Empty means no description was declared.
	//
	//	for _, metric := range store.Metrics() {
	//		fmt.Println(metric.Name, metric.Description)
	//	}
	Description string

	// Unit is the UCUM unit.
	// It describes values already recorded in that unit; no conversion is applied.
	//
	//	for _, metric := range store.Metrics() {
	//		fmt.Println(metric.Name, metric.Unit)
	//	}
	Unit string

	// Kind is the instrument kind.
	// Inspect it before interpreting Sum or Last as an aggregate result.
	//
	//	for _, metric := range store.Metrics() {
	//		if metric.Kind == telemetry.CounterKind {
	//			fmt.Println(metric.Name)
	//		}
	//	}
	Kind telemetry.InstrumentKind

	// Keys are the declared label keys in declaration order.
	// Every Point.Values entry has the corresponding position in this slice.
	//
	//	for _, metric := range store.Metrics() {
	//		fmt.Println(metric.Name, metric.Keys)
	//	}
	Keys []string

	// Points are the aggregates, one per label combination in order of first
	// recording.
	//
	//	for _, metric := range store.Metrics() {
	//		for _, point := range metric.Points {
	//			fmt.Println(metric.Name, point.Values, point.Count)
	//		}
	//	}
	Points []Point
}

Metric is the snapshot of one instrument and its aggregates. Obtain it through Driver.Metrics; Points follow first-recording order and Point looks up one exact declared label tuple without mutating the snapshot.

for _, metric := range store.Metrics() {
	if point, ok := metric.Point("hit"); ok {
		fmt.Println(metric.Name, point.Count, point.Sum)
	}
}

func (Metric) Point

func (metric Metric) Point(values ...string) (Point, bool)

Point returns the aggregate whose label values equal values, given in declared key order. The result owns its Values slice; editing it does not change metric or another lookup. No match returns the zero Point and false.

for _, metric := range driver.Metrics() {
	if point, ok := metric.Point("eu"); ok {
		fmt.Println(point.Sum)
	}
}

type Point

type Point struct {
	// Values are the label values, one per [Metric.Keys] entry in the same
	// order.
	// Point returns an owned copy of this slice for application-side edits.
	//
	//	if point, ok := metric.Point("hit"); ok {
	//		point.Values[0] = "display hit"
	//		fmt.Println(point.Values)
	//	}
	Values []string

	// Count is the number of recordings.
	// It is distinct from a counter's total increments or a histogram's sum.
	//
	//	if point, ok := metric.Point("hit"); ok {
	//		fmt.Println(point.Count)
	//	}
	Count uint64

	// Sum is the total of the recorded values.
	// For a counter this is its total, and for a histogram it is the value sum.
	//
	//	if point, ok := metric.Point("hit"); ok {
	//		fmt.Println(point.Sum)
	//	}
	Sum float64

	// Last is the most recently recorded value.
	// Use it for gauges rather than summing all samples over time.
	//
	//	if point, ok := metric.Point("primary"); ok {
	//		fmt.Println(point.Last)
	//	}
	Last float64
}

Point is the aggregate for one label combination.

Count is the number of recordings. Sum is the total of recorded values: the counter total, the up-down counter total, or the sum of a histogram. Last is the most recent value, which is the gauge value. Count counts calls, not counter increments; recording a counter increment of five contributes one to Count and five to Sum.

if point, ok := metric.Point("hit"); ok {
	fmt.Println(point.Count, point.Sum, point.Last)
}

type Span

type Span = telemetry.FinishedSpan

Span is the snapshot of a finished span: an alias of telemetry.FinishedSpan, so the spans the driver stores as a trace driver and the ones it receives as an telemetry.Observer have one shape. Its Attrs are in the order they were first set and Events holds recorded errors as events named "exception". Parent is the actual backend-selected parent supplied by SpanRecorder.Parent, not a reconstruction from the context seen by a passive observer.

span := memorytelemetry.Span{Name: "cache get", Attrs: []telemetry.Attr{telemetry.Bool("cached", true)}}
if attr, ok := span.Attr("cached"); ok {
	fmt.Println(attr.AsBool())
}

Directories

Path Synopsis
internal
aggregate
Package aggregate retains bounded, ordered metric label tuples.
Package aggregate retains bounded, ordered metric label tuples.
capture
Package capture copies and normalizes telemetry snapshots before storage.
Package capture copies and normalizes telemetry snapshots before storage.
tracegroup
Package tracegroup organizes retained span snapshots without storage or DTOs.
Package tracegroup organizes retained span snapshots without storage or DTOs.

Jump to

Keyboard shortcuts

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