gojihoney

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

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

Go to latest
Published: Jan 25, 2019 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Deprecated

Please use the Go Beeline instead, which has an updated goji middleware.

Deprecated

a goji middleware to log request data to http://honeycomb.io

Build Status

If you're already using the fantastic http://goji.io/, it's trivial to get request data flowing to a honeycomb dataset. It adds all fields of the http.Request object to the honeycomb event, as well as some additions:

  • GojiPattern useful as a normalized form of the request url
  • $prefix_$variable all variables from the GojiPattern are part of the event, prefixed by the string you pass into LogRequestToHoneycomb.
  • ResponseHttpStatus the http status code for this request
  • ResponseContentLength the amount of data written to the responseWriter
  • ResponseTime_ms total response time in milliseconds, as measured in the middleware around inner handler.

For more information about using Honeycomb, check out our docs and our Go SDK.

Example

package main

import (
        "fmt"
        "net/http"

        "goji.io"
        "goji.io/pat"
		
		"github.com/honeycombio/goji-honey"
)

func hello(w http.ResponseWriter, r *http.Request) {
        name := pat.Param(r, "name")
        fmt.Fprintf(w, "Hello, %s!", name)
}

func main() {
        mux := goji.NewMux()
		
		mux.Use(gojihoney.LogRequestToHoneycomb("gjv_"))
		
        mux.HandleFunc(pat.Get("/hello/:name"), hello)

        http.ListenAndServe("localhost:8000", mux)
}

Loading http://localhost:8000/hello/Charity will send an event to honeycomb with GojiPattern = /hello/:name, and gjv_name = Charity.

Extending the event

The event is sent at the end of request handling (in order to include response time, http status code, and response length), and can be extended by any inner handler during request handling, as in this possible change to hello above:

func hello(w http.ResponseWriter, r *http.Request) {
        name := pat.Param(ctx, "name")
		event := gojihoney.GetLibhoneyEvent(r.Context())
		
		before := time.Now()

		InsertHelloIntoDatabase(name)
		
		event.AddField("InsertTime_ms", time.Since(before).Seconds()*1000)
}

Goji and the context package

Goji's API was recently updated to use Go 1.7's standard library context package, which broke downstream unvendored packages like ours.

master in goji-honey tracks Goji's master, and thus uses the new context-based API.

Users of the old Goji API (found on Goji branch net-context) can find a goji-honey implementation on a branch of the same name: net-context.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLibhoneyEvent

func GetLibhoneyEvent(ctx context.Context) *libhoney.Event

func LogRequestToHoneycomb

func LogRequestToHoneycomb(varPrefix string) func(http.Handler) http.Handler

Middleware: log http.Requests and response HTTP status/content-length/time to Hound.

Types

This section is empty.

Jump to

Keyboard shortcuts

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