reqarchive

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

README

reqarchive package

The reqarchive package implements HTTP middleware (see midware package) for use in archiving HTTP requests to a service for debugging purposes. The handler stores the request URL path, query options, method, body and JWT claims in a JSON document. Requests must have a trace header (request ID) defined. This can be implemented with midware.TraceHeaders.

This package currently provider an implementation of the archiver middleware backed by AWS S3 which stores requests in a bucket keyed by request id under a prefix.

example usage

Given an HTTP handler, the below code wraps that with a request archiver:

func Listen(mainHandler http.Handler) error {
	archiver, err := NewS3Archiver("aws-region", "s3-bucket", "prefix")
	if err != nil {
		return err
	}
	middleware := midware.Chain{
		midware.TraceHeaders("", true),
		archiver,
	}
	handler := middleware.Wrap(mainHandler)
	return http.ListenAndServe(":8080", handler)
}

A separate S3 bucket should be configured with KMS encryption and a lifecycle rule to delete objects afer a short amount of time (7 days or so).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewS3Archiver

func NewS3Archiver(region, bucket, prefix string, opts ...Option) (midware.Middleware, error)

NewS3Archiver returns a middleware that archives requests to an AWS S3 bucket. The request bodies are copied then written to S3 in a separate goroutine. Requests are assumed to have a trace header (AKA request ID) implemented as the TraceHeaders middleware. The ID will be appended to prefix to generate the key for the request document.

Types

type Option

type Option func(*config)

Option represents an Archiver configuration option

func WithIgnoredPath

func WithIgnoredPath(path string) Option

WithIgnoredPath sets a URL path that will skipped by the archiver. It can be called more than once.

func WithLogBase

func WithLogBase(logBase *logrus.Entry) Option

WithLogBase sets a base logrus Entry for logging of errors.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for archival goroutines. Defaults to 1 minute.

func WithTraceHeader

func WithTraceHeader(header string) Option

WithTraceHeader overrides the default trace header.

Jump to

Keyboard shortcuts

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