Documentation
¶
Index ¶
- Constants
- func GenerateCorrelationID() string
- func GenerateRequestID() string
- func GetCorrelationID(ctx context.Context) string
- func GetOrGenerateRequestID(providedID string) string
- func GetRequestID(ctx context.Context) string
- func IsValidRequestID(id string) bool
- func ToolResultEnvelope(ctx context.Context) bool
- func WithCorrelationID(ctx context.Context, correlationID string) context.Context
- func WithMetadata(ctx context.Context, source RequestSource) context.Context
- func WithRequestID(ctx context.Context, requestID string) context.Context
- func WithRequestMeta(ctx context.Context, meta RequestMeta) context.Context
- func WithRequestSource(ctx context.Context, source RequestSource) context.Context
- func WithToolResultEnvelope(ctx context.Context) context.Context
- type ContextKey
- type Mount
- type RequestMeta
- type RequestSource
Constants ¶
const ( // RequestIDHeader is the HTTP header name for request IDs RequestIDHeader = "X-Request-Id" // MaxRequestIDLength is the maximum allowed length for a request ID MaxRequestIDLength = 256 )
Variables ¶
This section is empty.
Functions ¶
func GenerateCorrelationID ¶
func GenerateCorrelationID() string
GenerateCorrelationID generates a new unique correlation ID
func GenerateRequestID ¶
func GenerateRequestID() string
GenerateRequestID generates a new UUID v4 request ID
func GetCorrelationID ¶
GetCorrelationID retrieves the correlation ID from context
func GetOrGenerateRequestID ¶
GetOrGenerateRequestID returns the provided ID if valid, otherwise generates a new one. This is the main entry point for request ID handling in middleware.
func GetRequestID ¶
GetRequestID retrieves the request ID from context
func IsValidRequestID ¶
IsValidRequestID checks if a request ID matches the allowed pattern. Valid IDs contain only alphanumeric characters, dashes, and underscores, and are between 1 and 256 characters long.
func ToolResultEnvelope ¶ added in v0.72.0
func WithCorrelationID ¶
WithCorrelationID adds a correlation ID to the context
func WithMetadata ¶
func WithMetadata(ctx context.Context, source RequestSource) context.Context
WithMetadata adds both correlation ID and request source to context
func WithRequestID ¶
WithRequestID adds a request ID to the context
func WithRequestMeta ¶ added in v0.68.0
func WithRequestMeta(ctx context.Context, meta RequestMeta) context.Context
WithRequestMeta stores meta on the context.
func WithRequestSource ¶
func WithRequestSource(ctx context.Context, source RequestSource) context.Context
WithRequestSource adds request source to the context
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is the type for context keys to avoid collisions
const ( // CorrelationIDKey is the context key for correlation IDs CorrelationIDKey ContextKey = "correlation_id" // RequestSourceKey is the context key for request source RequestSourceKey ContextKey = "request_source" // RequestIDKey is the context key for request IDs (X-Request-Id header) RequestIDKey ContextKey = "request_id" // LoggerKey is the context key for request-scoped logger LoggerKey ContextKey = "logger" )
const RequestMetaKey ContextKey = "request_meta"
RequestMetaKey is the context key for RequestMeta.
type Mount ¶ added in v0.68.0
type Mount string
Mount names the HTTP mount a request entered through. It is fixed by the mount point (Spec 107 T050), never by a header.
type RequestMeta ¶ added in v0.68.0
RequestMeta is the per-request metadata the audit line needs (Spec 107 PR-D): the client IP as resolved through the trusted-proxy rule and the mount the request arrived on. RemoteAddr lives only on *http.Request, so the edition-neutral httpapi middleware stores it here.
func GetRequestMeta ¶ added in v0.68.0
func GetRequestMeta(ctx context.Context) (RequestMeta, bool)
GetRequestMeta returns the stored meta and whether one was set.
type RequestSource ¶
type RequestSource string
RequestSource indicates where the request originated
const ( // SourceRESTAPI indicates request came from HTTP REST API SourceRESTAPI RequestSource = "REST_API" // SourceCLI indicates request came from CLI command SourceCLI RequestSource = "CLI" // SourceMCP indicates request came from MCP protocol SourceMCP RequestSource = "MCP" // SourceInternal indicates internal/background operation SourceInternal RequestSource = "INTERNAL" // SourceUnknown indicates source could not be determined SourceUnknown RequestSource = "UNKNOWN" )
func GetRequestSource ¶
func GetRequestSource(ctx context.Context) RequestSource
GetRequestSource retrieves the request source from context