requestid

package
v2.3.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package requestid gives every gateway request one id of AI Studio's own.

The id is minted once, at the gateway's entry (Studio's proxy handler, the Microgateway's first middleware), and travels in the request context under the "request_id" key that plugins, hooks, filters and analytics already read. It is returned to the client in Header, never in X-Request-ID, which belongs to the client and to whatever proxies sit in front of the gateway: their X-Request-ID is passed through untouched and recorded as the client request id.

Ids look like "tyai_0192d8a4f6b37c1e9a5b2d4c6e8f0a1b": a fixed prefix, then a UUIDv7 in hex. UUIDv7 is ordered by time and carries 74 random bits, so ids minted on different nodes (edges, Studio replicas) do not collide; the prefix tells them apart from other systems' ids in shared logs.

Index

Constants

View Source
const (
	// Header carries the gateway's request id on every response, and on the
	// gateway's own loopback hop, where it is trusted only from that hop.
	Header = "X-Tyk-AI-Request-ID"
	// ClientHeader is the caller's own request id, recorded, never set.
	ClientHeader = "X-Request-ID"
	// Prefix starts every id this package mints.
	Prefix = "tyai_"
	// ContextKey is the context key the id is stored under. It is a plain
	// string because plugins and hooks have always read it that way.
	ContextKey = "request_id"
	// ClientContextKey holds the caller's sanitised X-Request-ID.
	ClientContextKey = "client_request_id"
	// MaxClientLen bounds a recorded client request id.
	MaxClientLen = 128
)

Variables

This section is empty.

Functions

func ClientFromContext

func ClientFromContext(ctx context.Context) string

ClientFromContext returns the caller's request id in ctx, "" when none.

func FromContext

func FromContext(ctx context.Context) string

FromContext returns the request id in ctx, "" when there is none.

func New

func New() string

New mints an id.

func SanitizeClient

func SanitizeClient(id string) string

SanitizeClient keeps a caller-supplied id to MaxClientLen characters of letters, digits and - _ . : / so it cannot write into a log line or event.

func Valid

func Valid(id string) bool

Valid reports whether id has the shape New gives, so a header value can be trusted to be one of ours and not text chosen to write into logs.

func WithID

func WithID(ctx context.Context, id, clientID string) context.Context

WithID stores id (and the caller's id, when not empty) in ctx.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL