beeline-go: github.com/honeycombio/beeline-go/wrappers/hnynethttp Index | Examples | Files

package hnynethttp

import "github.com/honeycombio/beeline-go/wrappers/hnynethttp"

Package hnynethttp provides Honeycomb wrappers for net/http Handlers.

Summary

hnynethttp provides wrappers for the `net/http` types: Handler and HandlerFunc

For best results, use WrapHandler to wrap the mux passed to http.ListenAndServe - this will get you an event for every HTTP request handled by the server.

Wrapping individual Handlers or HandleFuncs will generate events only for the endpoints that are wrapped; 404s, for example, will not generate events.

For a complete example showing this wrapper in use, please see the examples in https://github.com/honeycombio/beeline-go/tree/master/examples

Index

Examples

Package Files

doc.go nethttp.go

func WrapHandler Uses

func WrapHandler(handler http.Handler) http.Handler

WrapHandler will create a Honeycomb event per invocation of this handler with all the standard HTTP fields attached. If passed a ServeMux instead, pull what you can from there

Code:

// assume you have a handler named hello
var hello func(w http.ResponseWriter, r *http.Request)

globalmux := http.NewServeMux()
// add a bunch of routes to the muxer
globalmux.HandleFunc("/hello/", hello)

// wrap the globalmux with the honeycomb middleware to send one event per
// request
http.ListenAndServe(":8080", WrapHandler(globalmux))

func WrapHandlerFunc Uses

func WrapHandlerFunc(hf func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

WrapHandlerFunc will create a Honeycomb event per invocation of this handler function with all the standard HTTP fields attached.

Code:

// assume you have a handler function named helloServer
var helloServer func(w http.ResponseWriter, r *http.Request)

http.HandleFunc("/hello", WrapHandlerFunc(helloServer))

func WrapRoundTripper Uses

func WrapRoundTripper(r http.RoundTripper) http.RoundTripper

WrapRoundTripper wraps an http transport for outgoing HTTP calls. Using a wrapped transport will send an event to Honeycomb for each outbound HTTP call you make. Include a context with outbound requests when possible to enable correlation

Package hnynethttp imports 9 packages (graph) and is imported by 7 packages. Updated 2019-01-17. Refresh now. Tools for package owners.