[Proposal] Standardized Logging for Policy Developers #748
renuka-fernando
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Provide a standardized logging mechanism for policy developers by injecting a pre-configured
*slog.Loggerinto the policy factory function. This ensures consistent log formatting across all policies, automatic policy identification in logs, and simplifies the developer experience.Motivation
Problem Statement
Currently, policies use Go's
log/slogdirectly with manual conventions:"JWT Auth Policy: ...")Example of current inconsistent logging:
Who Benefits
policyandrequestIdfieldsWhy Now
Detailed Design
Overview
The policy engine will create a pre-configured
*slog.Loggerwith the policy name as a structured field and pass it to the policy factory function. An SDK helper functionWithRequestID()will allow policies to enrich logs with request correlation IDs during request/response processing. This approach requires no changes toPolicyMetadataand keeps the logger creation logic centralized in the policy engine.Changes Required
sdk/gateway/policy/v1alpha/interface.goPolicyFactorysignature to addlogger *slog.Loggerparametersdk/gateway/policy/v1alpha/logger.goWithRequestID()helper functiongateway/policy-engine/internal/registry/registry.gogateway/policies/*/GetPolicysignature and use provided loggerAPI Changes
N/A - No REST API changes.
Configuration Changes
N/A - No configuration changes.
Examples
Before:
After:
Log Output (Text format):
Log Output (JSON format):
{"level":"DEBUG","policy":"my-policy","msg":"Initializing","param":"value"} {"level":"DEBUG","policy":"my-policy","requestId":"abc-123","msg":"Processing request","path":"/pets"}Drawbacks
GetPolicyfunction signatureAlternatives Considered
Alternative 1: SDK Logger Utility Function
policy.NewLogger(metadata, policyName, policyVersion)that policies call to create their own loggerAlternative 2: Logger in PolicyMetadata
Logger *slog.Loggerfield toPolicyMetadatastructAlternative 3: No Change - Document Convention
Compatibility
PolicyFactorysignature changesGetPolicysignaturePolicyFactoryfunction signature addsloggerparameterMigration Steps
PolicyFactorysignature andWithRequestID()helperGetPolicyfunction to acceptlogger *slog.Loggerslog.Debug("Policy Name: ...")calls withlogger.Debug("...")policy.WithRequestID(logger, ctx.RequestID)for request-scoped loggingDefinition of Done
PolicyFactorysignature updated in SDKWithRequestID()helper added to SDKpolicyfieldReferences
Beta Was this translation helpful? Give feedback.
All reactions