Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emanuelef/go-fiber-honeycomb

Example of instrumenting a Go Fiber app and export traces to Honeycomb.io
https://github.com/emanuelef/go-fiber-honeycomb

fiber-framework go honeycombio observability opentelemetry opentelemetry-go

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# go-fiber-honeycomb

[![Golangci Lint Check](https://github.com/emanuelef/go-fiber-honeycomb/actions/workflows/golangci-lint.yml/badge.svg)](https://github.com/emanuelef/go-fiber-honeycomb/actions/workflows/golangci-lint.yml)

## Introduction

This is the repo for the Medium Article [Start using OpenTelemetry with Go Fiber](https://medium.com/@emafuma/start-using-opentelemetry-with-go-fiber-1005697d841f).
The aim is to show how to instrument with [OpenTelemetry](https://opentelemetry.io) a web server written in Go using the [Fiber framework](https://gofiber.io).
In order to see the traces generated [Honeycomb.io](https://www.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.

https://github.com/emanuelef/go-fiber-honeycomb/assets/48717/0f7938f7-e08e-4de2-93e2-a2b2e8026b47

First you need to get an API token from Honeycomb.io, you can sign up [here](https://ui.honeycomb.io/signup), 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:
```shell
./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:

```shell
docker compose up --build
```
Or they can be run individually with
```shell
go run main.go
```
from each folder:

- Main app runs on port 8080
- Secondary app on port 8082
- gRPC server on port 7070

```shell
curl http://127.0.0.1:8080/hello
```

To call all the endpoints implemented in the main app:
```shell
./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](opentelemetry_setup.go) 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](set_token.sh) script. Or it can be just copied from the .env.example file replacing the API token.

### GoFiberExample app

[GoFiberExample](main.go) 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 otelfiber.
- /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](secondary/main.go)
- /hello-http-client: Similar to /hello-otelhttp but using http.Client
- /hello-resty: Similar to /hello-otelhttp but using [Resty](https://github.com/go-resty/resty)
- /hello-grpc: Makes a gRPC requesto to the [grpc-server](grpc-server/main.go)