logging

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package logging provides structured logging utilities for gRPC services. Its primary export is CanonicalLogInterceptor, which emits a single "canonical log line" for every gRPC call - a structured slog record containing the method name, gRPC status code, response duration, caller identity, request ID, and trace context. These canonical lines serve as the authoritative audit trail for all service-to-service traffic and are designed to be queried in log aggregation backends (e.g. Datadog, Loki) for latency analysis, error investigation, and access auditing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalLogInterceptor

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

CanonicalLogInterceptor returns a gRPC unary server interceptor that emits one structured log line per RPC at INFO level. The log message is the full gRPC method name (e.g. "/auth.v1.AuthService/LoginUser") and the record includes:

  • type: always "canonical-log-line" (for log-query filtering)
  • grpc_method: full gRPC method name
  • grpc_code: gRPC status code string (e.g. "OK", "NotFound")
  • duration_ms: handler execution time in fractional milliseconds
  • request_id: from appctx.GetRequestID, if present in context
  • auth_type: identity type (user, api_key, agent, unauthenticated)
  • user_id / key_id / agent_id: actor ID, depending on auth type
  • target_account_id: account scope, if present
  • account_mode: production / test, if present
  • trace_id, span_id: from the active OpenTelemetry span, if recording
  • error: error message string, if the handler returned an error

This interceptor must be placed at the end of the interceptor chain so that upstream interceptors (identity extraction, request-ID propagation) have already populated the context values it reads.

Types

This section is empty.

Jump to

Keyboard shortcuts

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