We use cookies or similar technologies to personalize your online experience and tailor marketing to you. Many of our product features require cookies to function properly. Your use of this site and online product constitutes your consent to these personalization technologies. Read our Privacy Policy to find out more.


Honeycomb Beeline for Go - tutorial

The Honeycomb Beeline for Go includes several wrappers to capture data from different sources. Here is a walkthrough of installing and using the hnynethttp wrapper for net/http handlers.

Go Beeline tutorial roadmap

In this tutorial, we will:


You will need the following to complete this tutorial:

Installing Go is beyond the scope of this tutorial, but you can find more on the Go Getting Started page.

Install the Go Beeline

To install the Go Beeline, run this command in your $GOROOT directory:

$ go get github.com/honeycombio/beeline-go/...

$GOROOT is your Go install location. You should have set this environment variable as part of the Go installation process.

Configure the hnynethttp example

We are using the func WrapHandler example from the hnynethttp GoDoc page. It listens for requests on port 8080 and outputs events to STDOUT.

Copy the code from the nethttp example section to a convenient location (such as ~/hnynethttp-example.go.) It does not need to be in your $GOROOT directory.

If port 8080 is in use on your system, you can edit the ListenAndServe call to use a different port:

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

Generate events to STDOUT

To start your process and listen for requests, run the following command:

$ go run hnynethttp-example.go

Then, in a different shell, use curl to send it a request:

$ curl localhost:8080/hello/

The Beeline generates an event and outputs it to STDOUT in your original shell:


Send events to Honeycomb

Now that you have successfully generated events, send them to your Honeycomb dataset. Edit the example’s beeline.Init call to add your API key and dataset name, and also remove the line STDOUT: true,. Your initialization call should look like this:

    // Initialize beeline. The only required field is WriteKey.
        WriteKey: "YOUR_API_KEY",
        Dataset:  "my-dataset",

You are currently logged in to the team, so we have populated the write key here to the first write key for that team.

Now when you trigger a request with curl, the generated event goes to your Honeycomb dataset.

To add additional custom fields, add a line like this:

beeline.AddField(r.Context(), "more_custom", "Bzz Bzz Bzz")