trace

package
Version: v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package trace implement structured logging of requests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Tracer) error

Option is a functional option setter for Tracer

func ErrorHandler

func ErrorHandler(h utils.ErrorHandler) Option

ErrorHandler is a functional argument that sets error handler of the server

func Logger

func Logger(l utils.Logger) Option

Logger defines the logger the tracer will use.

func RequestHeaders

func RequestHeaders(headers ...string) Option

RequestHeaders adds request headers to capture

func ResponseHeaders

func ResponseHeaders(headers ...string) Option

ResponseHeaders adds response headers to capture

type Record

type Record struct {
	Request  Request  `json:"request"`
	Response Response `json:"response"`
}

Record represents a structured request and response record

type Request

type Request struct {
	Method    string      `json:"method"`            // Method - request method
	BodyBytes int64       `json:"body_bytes"`        // BodyBytes - size of request body in bytes
	URL       string      `json:"url"`               // URL - Request URL
	Headers   http.Header `json:"headers,omitempty"` // Headers - optional request headers, will be recorded if configured
	TLS       *TLS        `json:"tls,omitempty"`     // TLS - optional TLS record, will be recorded if it's a TLS connection
}

Request contains information about an HTTP request

type Response

type Response struct {
	Code      int         `json:"code"`              // Code - response status code
	Roundtrip float64     `json:"roundtrip"`         // Roundtrip - round trip time in milliseconds
	Headers   http.Header `json:"headers,omitempty"` // Headers - optional headers, will be recorded if configured
	BodyBytes int64       `json:"body_bytes"`        // BodyBytes - size of response body in bytes
}

Response contains information about HTTP response

type TLS

type TLS struct {
	Version     string `json:"version"`      // Version - TLS version
	Resume      bool   `json:"resume"`       // Resume tells if the session has been re-used (session tickets)
	CipherSuite string `json:"cipher_suite"` // CipherSuite contains cipher suite used for this connection
	Server      string `json:"server"`       // Server contains server name used in SNI
}

TLS contains information about this TLS connection

type Tracer

type Tracer struct {
	// contains filtered or unexported fields
}

Tracer records request and response emitting JSON structured data to the output

func New

func New(next http.Handler, writer io.Writer, opts ...Option) (*Tracer, error)

New creates a new Tracer middleware that emits all the request/response information in structured format to writer and passes the request to the next handler. It can optionally capture request and response headers, see RequestHeaders and ResponseHeaders options for details.

func (*Tracer) ServeHTTP

func (t *Tracer) ServeHTTP(w http.ResponseWriter, req *http.Request)

Source Files

Jump to

Keyboard shortcuts

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