observability

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRequestAttributes added in v0.27.0

func AddRequestAttributes(ctx context.Context, attrs ...attribute.KeyValue)

AddRequestAttributes sets attributes on both the current trace span and the finish log of the current request.

func GrpcPeer added in v0.29.0

func GrpcPeer(ctx context.Context) string

GrpcPeer returns the client address, using the "real" IP passed by the load balancer if available.

func HTTPPeer added in v0.29.0

func HTTPPeer(r *http.Request) string

HTTPPeer returns the client address, using the "real" IP passed by the load balancer if available.

func LoggingMiddleware

func LoggingMiddleware(logger *zap.Logger, next http.Handler) http.Handler

LoggingMiddleware is a HTTP request logging middleware. Note: It also recovers from panics and handles them as internal errors.

func LoggingStreamServerInterceptor

func LoggingStreamServerInterceptor(logger *zap.Logger) grpc.StreamServerInterceptor

LoggingStreamServerInterceptor is a gRPC streaming interceptor that logs requests. It also recovers from panics and returns them as internal errors.

func LoggingUnaryServerInterceptor

func LoggingUnaryServerInterceptor(logger *zap.Logger) grpc.UnaryServerInterceptor

LoggingUnaryServerInterceptor is a gRPC unary interceptor that logs requests. It also recovers from panics and returns them as internal errors.

func Middleware

func Middleware(serviceName string, logger *zap.Logger, next http.Handler) http.Handler

Middleware is HTTP middleware that combines all observability-related middlewares.

func Must

func Must[T any](val T, err error) T

func TracingMiddleware

func TracingMiddleware(next http.Handler, serviceName string) http.Handler

TracingMiddleware is HTTP middleware that adds tracing to the request.

func TracingStreamServerInterceptor

func TracingStreamServerInterceptor() grpc.StreamServerInterceptor

TracingStreamServerInterceptor is the streaming equivalent of TracingUnaryServerInterceptor

func TracingUnaryServerInterceptor

func TracingUnaryServerInterceptor() grpc.UnaryServerInterceptor

TracingUnaryServerInterceptor is a gRPC unary interceptor that adds tracing to the request.

func ZapCtx

func ZapCtx(ctx context.Context) zap.Field

ZapCtx returns a Zap field that adds "trace_id" and "span_id" fields to the log message

Types

type Exporter

type Exporter string

Exporter lists available telemetry exporters

const (
	NoopExporter       Exporter = ""
	OtelExporter       Exporter = "otel"
	PrometheusExporter Exporter = "prometheus"
)

type Options

type Options struct {
	MetricsExporter Exporter
	TracesExporter  Exporter
	ServiceName     string
	ServiceVersion  string
}

Options for configuring telemetry setup

type ShutdownFunc

type ShutdownFunc func(context.Context) error

ShutdownFunc stops global telemetry

func Start

func Start(ctx context.Context, logger *zap.Logger, opts *Options) (ShutdownFunc, error)

Start configures traces and metrics globally. Use "go.opentelemetry.io/otel.Tracer" to access global tracers. Use "go.opentelemetry.io/otel.Meter" to access global meters. If using OtelExporter (otel collector), make sure to set the OTEL_EXPORTER_OTLP_ENDPOINT env var. For a full list of Otel env vars, see: https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters/otlp/otlptrace.

Jump to

Keyboard shortcuts

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