telemetry

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedEngines = []Engine{EngineJaeger, EngineGrafana}

SupportedEngines lists all valid engine names for user-facing help text.

Functions

func BuildOTLPPayload added in v0.29.0

func BuildOTLPPayload(name string, duration time.Duration, attrs ...Attribute) ([]byte, error)

BuildOTLPPayload is exported for testing — constructs the OTLP JSON payload without actually sending it.

func ClearMetrics added in v0.29.0

func ClearMetrics() error

ClearMetrics truncates the local metrics file.

func ContainerName

func ContainerName(engine Engine) string

ContainerName returns the deterministic container name for a given engine.

func DiscoverOTEL

func DiscoverOTEL(runtime string) map[string]string

DiscoverOTEL scans running containers for any devx-managed telemetry backend. It returns the environment variable map to inject into devx shell, including OTEL_EXPORTER_OTLP_ENDPOINT and standard exporter wiring.

func ExportSpan added in v0.29.0

func ExportSpan(name string, duration time.Duration, attrs ...Attribute)

ExportSpan posts a single span to the local OTLP/HTTP endpoint. Fire-and-forget: silently no-ops if the backend is unreachable.

func Flush added in v0.30.0

func Flush()

Flush waits up to 100ms for pending OTLP exports to complete. Call this before exiting the CLI to ensure telemetry spans aren't dropped.

func InjectJSONFlag added in v0.30.0

func InjectJSONFlag(args []string) []string

InjectJSONFlag returns a copy of args with -json inserted after "test" if not already present. It returns the original args if -json exists.

func IsGoTestCmd added in v0.30.0

func IsGoTestCmd(args []string) bool

IsGoTestCmd returns true if the command is "go test".

func NudgeIfSlow added in v0.29.0

func NudgeIfSlow(event string, duration, threshold time.Duration, jsonMode bool)

NudgeIfSlow prints an actionable tip to stderr if duration exceeds threshold. Suppressed when jsonMode is true (for --json flag compliance).

func ProvisionDashboard added in v0.29.0

func ProvisionDashboard() error

ProvisionDashboard auto-installs the "devx Build Metrics" dashboard into a running Grafana instance. Fire-and-forget: warns on error but never fatals.

func RecordEvent added in v0.29.0

func RecordEvent(event string, duration time.Duration, attrs ...Attribute)

RecordEvent appends a timestamped duration entry to ~/.devx/metrics.json and opportunistically exports an OTel span to localhost:4318 if a backend is running. Safe for concurrent use (file-level flock). Silently no-ops on any I/O error.

func RunGoTestWithTelemetry added in v0.30.0

func RunGoTestWithTelemetry(args []string, dir string, stdout io.Writer, stderr io.Writer) (int, error)

RunGoTestWithTelemetry runs the wrapped go test -json command, parses output, emits spans, and reconstructs stdout.

func SpawnArgs

func SpawnArgs(engine Engine, runtime, persistDir string) ([]string, engineConfig, error)

SpawnArgs constructs the container run arguments for the given engine. If persistDir is non-empty, the host directory is bind-mounted into the container to preserve data across restarts.

Types

type Attribute added in v0.29.0

type Attribute struct {
	Key   string
	Value interface{}
}

Attribute is a key-value pair attached to an OTel span.

func Attr added in v0.29.0

func Attr(key string, value interface{}) Attribute

Attr is a convenience constructor for Attribute.

type Engine

type Engine string

Engine represents a supported local telemetry backend.

const (
	EngineJaeger  Engine = "jaeger"
	EngineGrafana Engine = "grafana"
)

type GoTestEvent added in v0.30.0

type GoTestEvent struct {
	Time    time.Time `json:"Time"`
	Action  string    `json:"Action"`
	Package string    `json:"Package"`
	Test    string    `json:"Test"`
	Elapsed float64   `json:"Elapsed"` // in seconds
	Output  string    `json:"Output"`
}

GoTestEvent mirrors the test2json output schema.

type MetricEntry added in v0.29.0

type MetricEntry struct {
	Event      string `json:"event"`
	DurationMs int64  `json:"duration_ms"`
	Timestamp  string `json:"timestamp"`
}

MetricEntry is a single recorded event.

func LoadMetrics added in v0.29.0

func LoadMetrics() []MetricEntry

LoadMetrics reads all metric entries from the local metrics file. Returns an empty slice (not nil) if the file is missing or corrupted.

Jump to

Keyboard shortcuts

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