Documentation
¶
Index ¶
Constants ¶
const StreamMetricsFinalizerKey = "__stream_metrics_finalizer"
StreamMetricsFinalizerKey is the fiber Locals key under which the metrics middleware stashes a StreamMetricsFinalizer for the proxy stream writer.
const StreamMetricsOwnedKey = "__stream_metrics_owned"
StreamMetricsOwnedKey is the fiber Locals key the proxy stream writer sets to signal that it owns the metrics emission for this request (via the finalizer). The middleware checks it on the way out and skips its own deferred emission, so a streamed request is emitted exactly once regardless of the response Content-Type.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type ContextKey ¶
type ContextKey string
ContextKey is the type used for request-scoped values stored in fiber Locals and the request context.Context. Stored under string(key) in Locals and under the typed key in context.Context, mirroring the metrics collector convention.
const ( // SessionContextKey holds the session identifier resolved by the session // middleware from the per-gateway session configuration. SessionContextKey ContextKey = "session_id" SessionGeneratedContextKey ContextKey = "session_id_generated" // TeamIDContextKey holds the team identifier decoded from an admin JWT. TeamIDContextKey ContextKey = "team_id" // UserIDContextKey holds the user identifier decoded from an admin JWT. UserIDContextKey ContextKey = "user_id" // UserEmailContextKey holds the user email decoded from an admin JWT. UserEmailContextKey ContextKey = "user_email" // MCPSkipMetricsKey is set by the MCP handler to tell the MCP metrics // middleware not to publish an event for the current request (e.g. ping, // notifications, or pre-dispatch failures). MCPSkipMetricsKey ContextKey = "__mcp_skip_metrics" )
type RequestContext ¶
type RequestContext struct {
Context context.Context
GatewayID string
ConsumerID string
RegistryID string
Headers map[string][]string
Method string
Path string
Query url.Values
Body []byte
Messages []string
Attachments []Attachment
Metadata map[string]interface{}
ProcessAt *time.Time
IP string
SessionID string
PreviousResponseID string
Provider string
SourceFormat string
TargetFormat string
AllowedModels []string
DefaultModel string
RequestedModel string
}
func (*RequestContext) HeaderValue ¶
func (r *RequestContext) HeaderValue(name string) string
HeaderValue returns the first non-empty value of the named header, matched case-insensitively. It returns "" when the header is absent or empty.
type ResponseContext ¶
type ResponseContext struct {
Context context.Context
GatewayID string
RegistryID string
Headers map[string][]string
Body []byte
StatusCode int
Streaming bool
TargetLatency float64
ProcessAt *time.Time
// Metadata carries values plugins pass across stages within a single
// request (e.g. cache status on PreRequest read back on PostResponse).
Metadata map[string]interface{}
}
type StreamMetricsFinalizer ¶
type StreamMetricsFinalizer func( req *RequestContext, output []byte, statusCode int, headers map[string][]string, )
StreamMetricsFinalizer emits metrics for a streamed response once its SSE body has been fully written.
The metrics middleware records request/response data on the way out via a deferred call, but a streamed body is flushed by fasthttp *after* the middleware returns, so at that point the captured output is empty. To close that gap the middleware stashes a finalizer in fiber Locals and skips its own emission for streaming responses; the proxy stream writer (which runs during body serialization) invokes the finalizer with the request context, the captured output bytes and the final response status/headers. The request context carries the observed token usage in its Metadata, which the metrics pipeline reads back when building the event.