request_log

package
v0.0.0-...-f22875c Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MigrateMutexKeyName = "request-log-migrate-lock"

MigrateMutexKeyName is the key that can be used when locking to perform a migration in redis.

View Source
const RequestLogRedisIndexName = "request_log_index_v1"

Variables

View Source
var ErrNotFound = errors.New("record not found")

ErrNotFound is returned when a log record is not found that was requested. This isn't necessarily a bad request as the record may have expired due to TTL.

Functions

func Migrate

func Migrate(ctx context.Context, rs redis.R, l *slog.Logger) error

Types

type Entry

type Entry struct {
	ID            uuid.UUID     `json:"id"`
	CorrelationID string        `json:"cid"`
	Timestamp     time.Time     `json:"ts"`
	Duration      time.Duration `json:"dur"`
	Request       EntryRequest  `json:"req"`
	Response      EntryResponse `json:"res"`
}

type EntryRecord

type EntryRecord struct {
	Type                RequestType   `json:"type"`
	RequestId           uuid.UUID     `json:"request_id"`
	CorrelationId       string        `json:"correlation_id,omitempty"`
	Timestamp           time.Time     `json:"timestamp"`
	Duration            time.Duration `json:"duration"`
	ConnectionId        uuid.UUID     `json:"connection_id,omitempty"`
	ConnectorType       string        `json:"connector_type,omitempty"`
	ConnectorId         uuid.UUID     `json:"connector_id,omitempty"`
	ConnectorVersion    uint64        `json:"connector_version,omitempty"`
	Method              string        `json:"method"`
	Host                string        `json:"host"`
	Scheme              string        `json:"scheme"`
	Path                string        `json:"path"`
	ResponseStatusCode  int           `json:"response_status_code,omitempty"`
	ResponseError       string        `json:"response_error,omitempty"`
	RequestHttpVersion  string        `json:"request_http_version,omitempty"`
	RequestSizeBytes    int64         `json:"request_size_bytes,omitempty"`
	RequestMimeType     string        `json:"request_mime_type,omitempty"`
	ResponseHttpVersion string        `json:"response_http_version,omitempty"`
	ResponseSizeBytes   int64         `json:"response_size_bytes,omitempty"`
	ResponseMimeType    string        `json:"response_mime_type,omitempty"`
}

EntryRecord represents a record of an HTTP request as is stored in the request log in redis. This data is redacted to avoid containing sensitive information like information in headers. For a given record in redis, the full request may be stored as well, which would correspond to the data in the Entry struct.

JSON tagging on this struct is used so the same data structure can be passed directly to endpoint responses. It is not use for internal storage.

func EntryRecordFromRedisFields

func EntryRecordFromRedisFields(vals map[string]string) (*EntryRecord, error)

EntryRecordFromRedisFields creates an EntryRecord from the redis fields. Note that the fields are a string/string map because that is what comes back from the go-redis client for RESP2 protocol.

type EntryRequest

type EntryRequest struct {
	URL           string              `json:"u"`
	HttpVersion   string              `json:"v"`
	Method        string              `json:"m"`
	Headers       map[string][]string `json:"h"`
	ContentLength int64               `json:"cl,omitempty"`
	Body          []byte              `json:"b,omitempty"`
}

type EntryResponse

type EntryResponse struct {
	HttpVersion   string              `json:"v"`
	StatusCode    int                 `json:"sc"`
	Headers       map[string][]string `json:"h"`
	Body          []byte              `json:"b,omitempty"`
	ContentLength int64               `json:"cl,omitempty"`
	Err           string              `json:"err,omitempty"`
}

type ListRequestExecutor

type ListRequestExecutor interface {
	FetchPage(context.Context) pagination.PageResult[EntryRecord]
	Enumerate(context.Context, func(pagination.PageResult[EntryRecord]) (keepGoing bool, err error)) error
}

type LogRetriever

type LogRetriever interface {
	GetFullLog(ctx context.Context, id uuid.UUID) (*Entry, error)
	NewListRequestsBuilder() ListRequestBuilder
	ListRequestsFromCursor(ctx context.Context, cursor string) (ListRequestExecutor, error)
}

LogRetriever is an interface for retrieving logs. Used by the API to retrieve logs.

func NewRetrievalService

func NewRetrievalService(r apredis.R, cursorKey config.KeyData) LogRetriever

type Logger

type Logger interface {
	RoundTrip(req *http.Request) (*http.Response, error)
}

Logger is an interface for logging requests. This is used as a middleware for http.Client.

func NewRedisLogger

func NewRedisLogger(
	r redis.R,
	logger *slog.Logger,
	requestInfo RequestInfo,
	expiration time.Duration,
	recordFullRequest bool,
	fullRequestExpiration time.Duration,
	maxFullRequestSize uint64,
	maxFullResponseSize uint64,
	transport http.RoundTripper,
) Logger

type RequestInfo

type RequestInfo struct {
	Type             RequestType
	ConnectorType    string
	ConnectorId      uuid.UUID
	ConnectorVersion uint64
	ConnectionId     uuid.UUID
}

type RequestOrderByField

type RequestOrderByField string
const (
	RequestOrderByCreatedAt RequestOrderByField = "created_at"
)

type RequestType

type RequestType string
const (
	RequestTypeGlobal RequestType = "global"
	RequestTypeProxy  RequestType = "proxy"
	RequestTypeOAuth  RequestType = "oauth"
	RequestTypePublic RequestType = "public"
)

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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