httpxxray

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 10 Imported by: 3

Documentation

Overview

Package httpxxray adds AWS X-Ray support to the httpx library's robust HTTP client. See https://github.com/gogama/httpx.

Use the OnClient function to install X-Ray support in any httpx.Client:

cl := &httpx.Client{}               // Create robust HTTP client
httpxxray.OnClient(cl, nil)         // Install X-Ray plugin

When creating a request plan for the client to execute, use an X-Ray aware context, for example the aws.Context passed to a Lambda function handler.

pl := request.NewPlanWithContext(   // Make plan using X-Ray aware context
	xrayAwareContext,
	"GET",
	"https://www.example.com/things/123",
	nil,
)
e, err := cl.Do(pl)                 // Send request and read response

// If the context is sampled by X-Ray, the X-Ray trace for the HTTP
// request has now been emitted.

Use the OnHandlers function to install X-Ray support directly onto an httpx.HandlerGroup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnClient

func OnClient(client *httpx.Client, logger Logger) *httpx.Client

OnClient installs AWS X-Ray support onto an httpx Client.

If client's current handler group is nil, OnClient creates a new handler group, sets it as client's current handler group, and proceeds to install X-Ray support into the handler group. If the handler group is not nil, OnClient adds X-Ray support into the existing handler group. (Be aware of this behavior if you are sharing a handler group among multiple clients.)

Logger is used to log errors encountered by the plugin. The plugin does not produce any log messages in the ordinary course of operation and the logger is intended as a "just in case" debugging aid. To ignore errors, pass NopLogger (or nil, which is interpreted as NopLogger). However if you are using the plugin in a production system it is always prudent to use a viable logger.

func OnHandlers

func OnHandlers(handlers *httpx.HandlerGroup, logger Logger) *httpx.HandlerGroup

OnHandlers installs AWS X-Ray support onto an httpx HandlerGroup.

The handler group may not be nil - if it is, a panic will ensue.

Logger is used to log errors encountered by the plugin. The plugin does not produce any log messages in the ordinary course of operation and the logger is intended as a "just in case" debugging aid. To ignore errors, pass NopLogger (or nil, which is interpreted as NopLogger). However if you are using the plugin in a production system it is always prudent to use a viable logger.

Types

type Logger

type Logger interface {
	// Printf prints a message to the logger. Arguments are handled in
	// the manner of fmt.Printf.
	Printf(format string, v ...interface{})
}

Logger allows the X-Ray plugin to log issues it has encountered. The interface is compatible with the Go standard log.Logger.

Implementations of Logger must be safe for concurrent use by multiple goroutines.

type NopLogger

type NopLogger struct{}

NopLogger implements the Logger interface but ignores all messages sent to it. Use NopLogger if you are not interested in learning about issues encountered by the X-Ray plugin.

func (NopLogger) Printf

func (_ NopLogger) Printf(string, ...interface{})

Jump to

Keyboard shortcuts

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