apilogging

package module
v0.0.0-...-b156b49 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

apilogging

Overview

This is a simple logging utility that can help users working with a Google API client library based on google.golang.org/api/ to log HTTP-level interactions.

Within cloud.google.com/go/ there are several submodules that also work with this, as they are based on underlying discovery-based HTTP clients rather than gRPC. Notable libraries include:

  • cloud.google.com/go/bigquery
  • cloud.google.com/go/storage

See integration_test.go for examples of usage.

Background

This logger relies on wrapping one http.RoundTripper with an instrumented roundtripper. Thus, any changes to the http request made by the inner RoundTripper are not observable.

The Google API discovery client provides access to it's custom roundtripper via google.golang.org/api/transport/http. It allows the same pattern, where it accepts a wrapped base roundtripper. It modifies requests to add essential pieces to the request such as the authentication token, as well as secondary values that are communicated through additional headers.

When used, request flow ends up passing through the api client transport, then the intercepting logging transport, and then finally a vanilla http.DefaultTransport.

Disclaimer

This is not an officially supported Google product.

Documentation

Overview

Package apilogging aids debugging of API interactions by providing a reusable logging mechanism.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInterceptingRoundTripper

func NewInterceptingRoundTripper(cfg *LoggerConfig, wrapped http.RoundTripper) (http.RoundTripper, error)

NewInterceptingRoundTripper sets up a logging http.RoundTripper.

func NewLoggingHTTPClient

func NewLoggingHTTPClient(ctx context.Context, cfg *LoggerConfig) (*http.Client, error)

NewLoggingHTTPClient provides an instrumented HTTP client, which can be used for constructing an appropriate service-specific API client.

Types

type LoggerConfig

type LoggerConfig struct {
	// Scopes allows for the override of API scopes used by the underlying HTTP
	// api transport.  If not specified, uses the default cloud-platform scope.
	Scopes []string
	// Logging must contain an instance of a logger.
	Logger *log.Logger
	// CaptureFullRequest governs whether the body of the request is captured.
	CaptureFullRequest bool
	// CaptureFullResponse governs whether the body of the response is captured.
	CaptureFullResponse bool
	// LogRequest allows filtration based on the request body bytes.
	LogRequest func(b []byte) bool
	// LogResponse allows filtration based on the response body bytes.  Whether the
	// request was matched is also available.
	LogResponse func(b []byte, requestMatched bool) bool
}

LoggerConfig governs the behavior of the api logging.

Jump to

Keyboard shortcuts

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