Go is a statically typed, compiled language used here to build HTTP services and expose application behavior for observability. section 2.1 section 9.1.1
The examples use Go to:
- Build and run an echo service that listens on port 4242 and sometimes returns an internal server error. section 2.1
- Generate request load with curl so logs, metrics, and traces can be inspected using Grafana, Prometheus, and Jaeger. section 2.1
- Expose runtime profiles through net/http/pprof and inspect goroutines, heap allocations, and CPU usage. section 9.1.1
Instrumentable echo service
A small Go program registers an /echo handler, reads a message query parameter, writes the response, and serves HTTP on localhost:4242. Building it uses go build -o echosvc ., while repeated curl requests create activity for observability tools. section 2.1
Listing 2.1 Example Go program to be instrumented
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
)
func handleEcho(w http.ResponseWriter, r *http.Request) {
message := r.URL.Query().Get("message") #1
if rand.Intn(100) > 90 { #2
w.WriteHeader(http.StatusInternalServerError)
return
}
fmt.Fprintf(w, message) #3
}
func main() {
rand.Seed(time.Now().UnixNano())
http.HandleFunc("/echo", handleEcho) #4
log.Fatal(http.ListenAndServe(":4242", nil)) #5
}
Inspect the complete Go echo service, including its handler, randomized failure path, route registration, and HTTP server. section 2.1










