metrics

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MPL-2.0 Imports: 15 Imported by: 1 module, 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 metrics wires OpenTelemetry tracing and metrics for the chassis.

Configuration is via standard OTel environment variables:

  • OTEL_EXPORTER_OTLP_ENDPOINT (e.g. http://localhost:4318)
  • OTEL_EXPORTER_OTLP_PROTOCOL (http/protobuf | grpc)
  • OTEL_SERVICE_NAME (default: txco-chassis)
  • OTEL_RESOURCE_ATTRIBUTES (extra resource attributes)

If no OTLP endpoint is set the SDK still installs a working tracer/meter provider; spans and metrics are recorded in-process but not exported.

Index

Constants

View Source
const (
	AttrEventsSource = "txco.events.source"
	AttrOpName       = "txco.op.name"
	AttrTenantSlug   = "txco.tenant.slug"
	AttrSecretName   = "txco.secret.name"
)

Attribute keys used across the chassis. These follow OTel semantic-convention style (lower-snake-case, dotted namespace) so they roll up cleanly in any OTLP backend.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	Tracer trace.Tracer
	Meter  metric.Meter

	EventsReceived       metric.Int64Counter
	EventsResponseTimeMs metric.Int64Histogram
	OpTotal              metric.Int64Counter
	OpDurationMs         metric.Int64Histogram

	// SecretMaterialized increments once per (tenant_slug, secret_name)
	// reference the processor's splice resolves for an op (cache hit
	// or miss — both count as a reference). Lets operators detect a
	// runaway op that materializes the same secret thousands of times
	// per second, AND see the per-tenant access pattern for audit/
	// quota purposes. NEVER record the cleartext or the cleartext
	// length here — only the names.
	SecretMaterialized metric.Int64Counter
	// contains filtered or unexported fields
}

Metrics holds the chassis tracer, meter, and pre-built instruments.

func New

func New(ctx context.Context, conf config.Config, logger *zap.Logger) *Metrics

New initialises OTel providers and returns a Metrics with pre-built instruments. Call Metrics.Shutdown(ctx) before process exit to flush.

func (*Metrics) RecordEvent

func (m *Metrics) RecordEvent(ctx context.Context, source string, durationMs int64)

RecordEvent increments the events.received counter and records the events.response_time histogram, both tagged with the event source (web, tcp, cron, ...). Call once per envelope processed.

func (*Metrics) RecordOp

func (m *Metrics) RecordOp(ctx context.Context, opName string, durationMs int64)

RecordOp increments the op.count counter and records the op.duration histogram, both tagged with the operation name.

func (*Metrics) RecordSecretMaterialize

func (m *Metrics) RecordSecretMaterialize(ctx context.Context, tenantSlug, secretName string)

RecordSecretMaterialize increments the secret.materialize counter tagged with tenant slug + secret name. Nil-safe: if m or m.SecretMaterialized is nil (the chassis was built without metrics, e.g. some unit tests), this is a no-op. NEVER pass the cleartext or any portion of it — only the NAME.

func (*Metrics) Shutdown

func (m *Metrics) Shutdown(ctx context.Context) error

Shutdown flushes any pending telemetry. Call from main.go on signal.

Jump to

Keyboard shortcuts

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