Documentation
¶
Overview ¶
Package observer can be used for implementing observability using OpenTelemetry API. It aims to unify three pillars of observability in one single package that is easy-to-use and hard-to-misuse.
An Observer encompasses a logger, a meter, and a tracer. It offers a single unified developer experience for observability.
Index ¶
- func ContextWithLogger(ctx context.Context, logger Logger) context.Context
- func ContextWithMeter(ctx context.Context, meter metric.Meter) context.Context
- func ContextWithTracer(ctx context.Context, tracer trace.Tracer) context.Context
- func ContextWithUUID(ctx context.Context, uuid string) context.Context
- func MeterFromContext(ctx context.Context) metric.Meter
- func Set(o Observer)
- func TracerFromContext(ctx context.Context) trace.Tracer
- func UUIDFromContext(ctx context.Context) (string, bool)
- type Level
- type Logger
- type Observer
- type Option
- func WithJaeger(agentEndpoint, collectorEndpoint, collectorUserName, collectorPassword string) Option
- func WithLogger(level string) Option
- func WithMetadata(name, version, environment, region string, tags map[string]string) Option
- func WithOpenTelemetry(collectorAddress string, collectorCredentials credentials.TransportCredentials) Option
- func WithPrometheus() Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithLogger ¶
ContextWithLogger returns a new context that holds a reference to a logger.
func ContextWithMeter ¶
ContextWithMeter returns a new context that holds a reference to a meter.
func ContextWithTracer ¶
ContextWithTracer returns a new context that holds a reference to a tracer.
func ContextWithUUID ¶
ContextWithUUID creates a new context with a uuid.
func MeterFromContext ¶
MeterFromContext returns a meter set on a context. If no meter found on the context, the singleton meter will be returned!
func TracerFromContext ¶
TracerFromContext returns a tracer set on a context. If no tracer found on the context, the singleton tracer will be returned!
Types ¶
type Logger ¶
type Logger interface { Level() Level SetLevel(level string) With(kv ...interface{}) Logger Debug(message string, kv ...interface{}) Debugf(format string, args ...interface{}) Info(message string, kv ...interface{}) Infof(format string, args ...interface{}) Warn(message string, kv ...interface{}) Warnf(format string, args ...interface{}) Error(message string, kv ...interface{}) Errorf(format string, args ...interface{}) Close() error }
Logger is a levelled structured logger. It is concurrently safe to be used by multiple goroutines.
func LoggerFromContext ¶
LoggerFromContext returns a logger set on a context. If no logger found on the context, the singleton logger will be returned!
type Observer ¶
type Observer interface { http.Handler Name() string Logger() Logger Meter() metric.Meter Tracer() trace.Tracer Close(context.Context) error }
Observer provides logging, metrics, and tracing capabilities for observability.
type Option ¶
type Option func(*options)
Option is used for configuring an observer.
func WithJaeger ¶
func WithJaeger(agentEndpoint, collectorEndpoint, collectorUserName, collectorPassword string) Option
WithJaeger is the option for enabling Jaeger. Only one of agentEndpoint or collectorEndpoint is required. collectorUserName and collectorPassword are optional. The default agent endpoint is localhost:6831.
func WithLogger ¶
WithLogger is the option for enabling the logger.
func WithMetadata ¶
WithMetadata is the option for specifying and reporting metadata. All arguments are optional.
func WithOpenTelemetry ¶
func WithOpenTelemetry(collectorAddress string, collectorCredentials credentials.TransportCredentials) Option
WithOpenTelemetry is the option for enabling OpenTelemetry Collector. collectorCredentials is optional. If not specified, the connection will be insecure. The default collector address is localhost:55680.
func WithPrometheus ¶
func WithPrometheus() Option
WithPrometheus is the option for enabling Prometheus.
Directories
¶
Path | Synopsis |
---|---|
example
|
|
Package ohttp is an observable http package.
|
Package ohttp is an observable http package. |