Documentation
¶
Index ¶
- Constants
- Variables
- func NewContext(ctx context.Context, trace Trace) context.Context
- func RecordCount(ctx context.Context, metricName string, count uint64)
- func RecordDuration(ctx context.Context, metricName string, duration time.Duration)
- func RecordEvent(ctx context.Context, eventName string, kvPairs map[string]interface{})
- type MethodTracer
- type Provider
- type Request
- type Span
- type Trace
Constants ¶
const (
// ProviderContextKey is the context key used to store the metrics Provider
ProviderContextKey = "metrics_provider_context"
)
Variables ¶
var TraceKey = traceContextKey{}
TraceKey is the context key for Trace
Functions ¶
func NewContext ¶ added in v0.8.0
NewContext returns a new context with the trace attached
func RecordCount ¶
RecordCount records a count metric
func RecordDuration ¶
RecordDuration records a duration metric
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
TraceFromContext retrieves the trace from context, if present