observability

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTraceLoggerObservability

func NewTraceLoggerObservability(trace trace.Tracer, logger logger.LoggerInterface, counter *prometheus.CounterVec, duration *prometheus.HistogramVec) *traceLoggerObservability

NewTraceLoggerObservability creates a new traceLoggerObservability instance.

It takes context.Context, trace.Tracer, logger.LoggerInterface, prometheus.CounterVec, and prometheus.HistogramVec as input.

The returned traceLoggerObservability instance includes the input parameters and can be used to start tracing and logging, as well as recording metrics.

If the input context is canceled, the tracing and logging will be stopped.

Types

type TraceLoggerObservability

type TraceLoggerObservability interface {
	// StartTracingAndLogging initializes tracing and logging for a given method.
	// It starts a span with optional attributes and logs the method start.
	// It returns the context with the span, the span, a function to end the span and record metrics,
	// the initial status of the operation, and a function to log success messages.
	//
	// Parameters:
	//   - ctx: The context for the traced method.
	//   - method: The name of the method to trace and log.
	//   - attrs: Optional attributes to add to the span.
	//
	// Returns:
	//   - context.Context: The context with the span.
	//   - trace.Span: The OpenTelemetry span for the traced method.
	//   - func(string): Function to end the span with a given status, recording metrics.
	//   - string: Initial status of the operation, defaulting to "success".
	//   - func(string, ...zap.Field): Function to log success messages with optional fields.
	StartTracingAndLogging(ctx context.Context, method string, attrs ...attribute.KeyValue) (
		context.Context,
		trace.Span,
		func(string),
		string,
		func(string, ...zap.Field),
	)
	// RecordMetrics records a Prometheus metric for the given method and status.
	// It increments a counter and records the duration since the provided start time.
	RecordMetrics(method, status string, start time.Time)
}

TraceLoggerObservability provides tracing, logging, and request metrics.

Jump to

Keyboard shortcuts

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