grpckit

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package grpckit provides gRPC server utilities including standard interceptors for logging, panic recovery, and health-check registration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHealth

func RegisterHealth(server *grpc.Server, checker HealthChecker)

RegisterHealth registers a grpc.health.v1.Health service on the given gRPC server. The Check RPC calls the provided checker and maps the result to a gRPC health status: SERVING when the checker returns nil, NOT_SERVING when it returns an error.

func StreamLogging

func StreamLogging(logger *slog.Logger) grpc.StreamServerInterceptor

StreamLogging returns a stream server interceptor that logs the method name and duration for each stream RPC at Info level.

func StreamMetrics

func StreamMetrics() grpc.StreamServerInterceptor

StreamMetrics returns a stream server interceptor that records rpc.server.duration as an OTel histogram with method and status code attributes.

func StreamRecovery

func StreamRecovery(logger *slog.Logger) grpc.StreamServerInterceptor

StreamRecovery returns a stream server interceptor that catches panics in the handler, logs them at Error level, and returns a codes.Internal gRPC status.

func StreamTracing added in v1.4.0

func StreamTracing() grpc.StreamServerInterceptor

StreamTracing returns a stream server interceptor that creates an OpenTelemetry span for each stream RPC, recording the method name, gRPC status code, and any error. It extracts incoming W3C trace context from gRPC metadata so that spans are parented correctly in distributed traces.

func UnaryLogging

func UnaryLogging(logger *slog.Logger) grpc.UnaryServerInterceptor

UnaryLogging returns a unary server interceptor that logs the method name, duration, and error (if any) for each RPC at Info level.

func UnaryMetrics

func UnaryMetrics() grpc.UnaryServerInterceptor

UnaryMetrics returns a unary server interceptor that records rpc.server.duration as an OTel histogram with method and status code attributes.

func UnaryRecovery

func UnaryRecovery(logger *slog.Logger) grpc.UnaryServerInterceptor

UnaryRecovery returns a unary server interceptor that catches panics in the handler, logs them at Error level, and returns a codes.Internal gRPC status.

func UnaryTracing added in v1.4.0

func UnaryTracing() grpc.UnaryServerInterceptor

UnaryTracing returns a unary server interceptor that creates an OpenTelemetry span for each RPC, recording the method name, gRPC status code, and any error. It extracts incoming W3C trace context from gRPC metadata so that spans are parented correctly in distributed traces.

Types

type HealthChecker

type HealthChecker func(ctx context.Context) error

HealthChecker is a function that performs health checks and returns an error when any check fails. This decouples grpckit from the health package — callers typically pass the result of health.All(checks).

Jump to

Keyboard shortcuts

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