httplog

package
v1.70.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPListener = &crest.HTTPListener{
	Callback: func(response crest.RequestResponse) {
		id := uuid.NewString()
		ctx := context.TODO()
		if response.Request != nil && response.Request.Context() != nil {
			ctx = response.Request.Context()
		}
		if response.Request != nil {
			if response.Request.URL != nil {
				if response.Request.Body != nil {
					body, _ := io.ReadAll(response.Request.Body)
					rest.Logger.Printf(ctx, "[%s] %s %s", id, response.Request.Method, response.Request.URL.String())
					rest.Logger.Printf(ctx, "[%s] [PAYLOAD] %s", id, string(body))
				} else {
					rest.Logger.Printf(ctx, "[%s] %s %s", id, response.Request.Method, response.Request.URL.String())
				}
			}
		}
		if response.Response != nil {
			if response.Response.Body != nil {
				if os.Getenv("DYNATRACE_HTTP_RESPONSE") == "true" {
					body, _ := io.ReadAll(response.Response.Body)
					if body != nil {
						rest.Logger.Printf(ctx, "[%s] [RESPONSE] %d %s", id, response.Response.StatusCode, string(body))
					} else {
						rest.Logger.Printf(ctx, "[%s] [RESPONSE] %d", id, response.Response.StatusCode)
					}
				}
			}
		}
	},
}

Functions

func InstallRoundTripper added in v1.70.0

func InstallRoundTripper()

Types

type RoundTripper

type RoundTripper struct {
	RoundTripper http.RoundTripper
	// contains filtered or unexported fields
}

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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