Skip to content

Example of instrumenting a Go Gin app and export traces to Honeycomb.io

Notifications You must be signed in to change notification settings

emanuelef/go-gin-honeycomb

Repository files navigation

go-gin-honeycomb

Golangci Lint Check

Introduction

This is the repo for the Medium Article Start using OpenTelemetry with Go Gin Web Framework.
The aim is to show how to instrument with OpenTelemetry a web server written in Go using the Gin Web Framework.
In order to see the traces generated Honeycomb.io is used as the Observability solution.

Run code

The short video will show how to start the 3 apps with docker compose and run some http requests.

go-fiber-honeycomb.Codespace.demo.mp4

First you need to get an API token from Honeycomb.io, you can sign up here, the free plan is very generous, doesn't require to set up any payment and is time unlimited.

You can then run the example locally or using Codespaces, the steps are the same.

In order to populate the .env files needed by the the three apps run:

./set_token.sh

And paste the API Key from Honeycomb.io, it will appear at the end of the sign up or can be retrieved later in the Account > Team settings.

There are three apps to demonstrate the distributed tracing, to start them altogher run:

docker compose up --build

Or they can be run individually with

go run main.go

from each folder:

  • Main app runs on port 8080
  • Secondary app on port 8082
  • gRPC server on port 7070
curl http://127.0.0.1:8080/hello

To run all the endpoints implemented in the main app:

./run_http_requests.sh

Fome Home you will see the traces appearing at the bottom (or you can run a query)

Honeycomb Home

Clicking on the button on the left will open the Traces view

Honecomb resty traces

Code

Common code for setting up instrumentation

Otel Instrumentation has the public function to set up the Trace provider and exporter used by the apps. It get the env vars from the .env file that is generated by set_token script. Or it can be just copied from the .env.example file replacing the API token.

GoGinExample app

GoGinExample contains all the code for the main app listening on port 8080.

All the endpoints served are GETs without any query or path parameters.

  • /health: Does nothing and returns 200, added to demonstrate how is possible to exclude some endpoints in otelgin.
  • /hello: Returns 200 and is generating a trace
  • /hello-child: Creates a child span
  • /hello-otelhttp: Runs some HTTP GETs using otelhttp to a public external url and to the secondary app
  • /hello-http-client: Similar to /hello-otelhttp but using http.Client
  • /hello-resty: Similar to /hello-otelhttp but using Resty
  • /hello-grpc: Makes a gRPC requesto to the grpc-server

About

Example of instrumenting a Go Gin app and export traces to Honeycomb.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages