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.

X

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:

Requirements

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:

{"data":{"app.custom":"Wheee","duration_ms":0.043482,"handler.name":"main.hello","handler.pattern":"/hello/","handler.type":"http.HandlerFunc","meta.beeline_version":"0.1.0","meta.local_hostname":"myhost","meta.type":"http","name":"main.hello","request.content_length":0,"request.header.user_agent":"curl/7.47.0","request.host":"","request.http_version":"HTTP/1.1","request.method":"GET","request.path":"/hello/","request.remote_addr":"127.0.0.1:51542","response.status_code":200,"trace.span_id":"dabb4b77-7327-4843-9b82-c80cca77f1c0","trace.trace_id":"dd774987-0819-4217-8e4a-357fd9c1855f"},"time":"2018-05-09T22:42:52.894882763Z"}

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.
    beeline.Init(beeline.Config{
        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")