diff --git a/hlog/hlog.go b/hlog/hlog.go index 2026214..f7c3a5a 100644 --- a/hlog/hlog.go +++ b/hlog/hlog.go @@ -129,7 +129,12 @@ func IDFromRequest(r *http.Request) (id xid.ID, ok bool) { if r == nil { return } - id, ok = r.Context().Value(idKey{}).(xid.ID) + return IDFromCtx(r.Context()) +} + +// IDFromCtx returns the unique id associated to the context if any. +func IDFromCtx(ctx context.Context) (id xid.ID, ok bool) { + id, ok = ctx.Value(idKey{}).(xid.ID) return }