hnynethttp

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 12 Imported by: 68

README

Documentation available via godoc

Documentation

Overview

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/main/examples

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapHandler

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

Example
// 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))
Output:

func WrapHandlerFunc

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.

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

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

func WrapHandlerWithConfig added in v0.6.0

func WrapHandlerWithConfig(handler http.Handler, cfg config.HTTPIncomingConfig) http.Handler

WrapHandlerWithConfig 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. The provided config has a HTTPTraceParserHook, it will be invoked when creating a new span or trace for each incoming HTTP request.

func WrapRoundTripper added in v0.2.0

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

func WrapRoundTripperWithConfig added in v0.6.0

func WrapRoundTripperWithConfig(r http.RoundTripper, cfg config.HTTPOutgoingConfig) http.RoundTripper

WrapRoundTripperWithConfig is a version of WrapRoundTripper that accepts a config. If the config contains a HTTPTracePropagationHook, it will be invoked on each outgoing HTTP call. The return value, a map of header names to header strings, will be added to the headers of the outgoing request.

Types

This section is empty.

Jump to

Keyboard shortcuts

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