mirror of
https://github.com/zap-proto/zip.git
synced 2026-10-19 15:38:57 +00:00
zip is shared protocol infra (the fiber-over-ZAP web framework used by every
Lux/Hanzo/Zoo Go binary — nodes, gateway, cloud, iam, kms, o11y, ai, …), so its
home is the ZAP protocol family (zap-proto/{go,http,zapd,zip}), NOT any one org's
brand namespace. This consolidates the rich framework (formerly hanzoai/zip v0.5.0
— Ctx/Handler/Errorf/Err*/HTTPError, typed handlers, middleware, runtime/extension
loading, openapi, validate, zaprpc) with the real ZAP transport (ListenZAP/
ListenHTTP/Serve over zap-proto/http) into ONE canonical module.
Module path github.com/hanzoai/zip -> github.com/zap-proto/zip. Code identical to
hanzoai/zip v0.5.0; promoted to v1.0.0 as the stable shared-infra framework. The
prior hanzoai/zip lineage is retired — one home, one import path, one way.
Verified: go build/vet/test ./... green; the ZAP round-trip integration test serves
/v1/health over the real ZAP transport (200 + handler JSON).
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/zap-proto/zip"
|
|
)
|
|
|
|
// O11ySink is the minimum interface zip's telemetry middleware consumes.
|
|
// Real implementations live in hanzoai/insights / o11y SDKs. nil sink =
|
|
// no-op middleware.
|
|
type O11ySink interface {
|
|
// Record reports a single request to the o11y backend.
|
|
Record(method, path string, status int, dur time.Duration, attrs map[string]string)
|
|
}
|
|
|
|
// Telemetry returns middleware that records every request through sink.
|
|
// Use this alongside Logger() (which writes to luxfi/log); Telemetry()
|
|
// is for structured metrics/traces flowing to o11y backends.
|
|
func Telemetry(sink O11ySink) zip.Handler {
|
|
if sink == nil {
|
|
return func(c *zip.Ctx) error { return c.Continue() }
|
|
}
|
|
return func(c *zip.Ctx) error {
|
|
start := time.Now()
|
|
err := c.Continue()
|
|
dur := time.Since(start)
|
|
attrs := map[string]string{}
|
|
if rid := c.RequestID(); rid != "" {
|
|
attrs["request_id"] = rid
|
|
}
|
|
if org := c.Org(); org != "" {
|
|
attrs["org"] = org
|
|
}
|
|
sink.Record(c.Method(), c.Path(), c.Fiber().Response().StatusCode(), dur, attrs)
|
|
return err
|
|
}
|
|
}
|