metrics

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProviderContextKey is the context key used to store the metrics Provider
	ProviderContextKey = "metrics_provider_context"
)

Variables

View Source
var TraceKey = traceContextKey{}

TraceKey is the context key for Trace

Functions

func NewContext added in v0.8.0

func NewContext(ctx context.Context, trace Trace) context.Context

NewContext returns a new context with the trace attached

func RecordCount

func RecordCount(ctx context.Context, metricName string, count uint64)

RecordCount records a count metric

func RecordDuration

func RecordDuration(ctx context.Context, metricName string, duration time.Duration)

RecordDuration records a duration metric

func RecordEvent

func RecordEvent(ctx context.Context, eventName string, kvPairs map[string]interface{})

RecordEvent records a new event with a name and set of key-value pairs

Types

type MethodTracer

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

MethodTracer collects analytics for a given method call within an existing trace.

func TraceMethodCall

func TraceMethodCall(ctx context.Context, structOrPackageName, methodName string) *MethodTracer

TraceMethodCall traces a method call with a given struct/package and method names

func (*MethodTracer) AddAttribute

func (t *MethodTracer) AddAttribute(key string, value interface{})

AddAttribute adds a key-value pair metadata to the method trace

func (*MethodTracer) AddAttributes

func (t *MethodTracer) AddAttributes(attributes map[string]interface{})

AddAttributes adds a set of key-value pair metadata to the method trace

func (*MethodTracer) End

func (t *MethodTracer) End()

End completes the trace for the method call.

func (*MethodTracer) OnError

func (t *MethodTracer) OnError(err error)

OnError observes an error within a method trace

type Provider added in v0.8.0

type Provider interface {
	// StartTrace starts a new trace
	StartTrace(name string) Trace

	// RecordEvent records a custom event with key-value attributes
	RecordEvent(eventName string, attributes map[string]interface{})

	// RecordCount records a count metric
	RecordCount(metricName string, count uint64)

	// RecordDuration records a duration metric
	RecordDuration(metricName string, duration time.Duration)
}

Provider defines an abstract metrics provider that can record events, metrics, and traces. This allows swapping between different backends (New Relic, Datadog, Prometheus, no-op, etc.).

type Request added in v0.8.0

type Request struct {
	Header    http.Header
	URL       interface{} // *url.URL
	Method    string
	Transport string
}

Request contains HTTP request information for tracing

type Span added in v0.8.0

type Span interface {
	// AddAttribute adds a key-value attribute to the span
	AddAttribute(key string, value interface{})

	// End completes the span
	End()
}

Span represents a timed span within a trace for tracing individual operations.

type Trace added in v0.8.0

type Trace interface {
	// StartSpan starts a new span within the trace
	StartSpan(name string) Span

	// AddAttribute adds a key-value attribute to the trace
	AddAttribute(key string, value interface{})

	// OnError records an error on the trace
	OnError(err error)

	// SetRequest sets HTTP request information on the trace
	SetRequest(r Request)

	// SetResponse sets the HTTP response writer for the trace
	SetResponse(w http.ResponseWriter) http.ResponseWriter

	// End completes the trace
	End()
}

Trace represents an active trace that can contain multiple spans and attributes.

func TraceFromContext added in v0.8.0

func TraceFromContext(ctx context.Context) Trace

TraceFromContext retrieves the trace from context, if present

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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