Echo
Instrument Go Echo v4 applications with the Last9 Go Agent for automatic HTTP request tracing, database monitoring, and distributed system observability
Use the Last9 Go Agent to instrument your Echo v4 application with automatic tracing and metrics. The agent wraps the official otelecho package under the hood — so you get full OpenTelemetry compliance with minimal code changes.
Prerequisites
- Go 1.22 or higher
- Echo v4 (
github.com/labstack/echo/v4) - Last9 account with OTLP credentials
Installation
-
Install the Last9 Go Agent
go get github.com/last9/go-agent -
Set Environment Variables
export OTEL_SERVICE_NAME="your-echo-service"export OTEL_EXPORTER_OTLP_ENDPOINT="$last9_otlp_endpoint"export OTEL_EXPORTER_OTLP_HEADERS="Authorization=$last9_otlp_auth_header"export OTEL_TRACES_SAMPLER="always_on"export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=production" -
Instrument your application
Replace
echo.New()withechoagent.New()— that’s the only change required:package mainimport ("net/http""log""github.com/labstack/echo/v4""github.com/last9/go-agent"echoagent "github.com/last9/go-agent/instrumentation/echo")func main() {if err := agent.Start(); err != nil {log.Fatalf("Failed to start agent: %v", err)}defer agent.Shutdown()// Drop-in replacement for echo.New()e := echoagent.New()e.GET("/", func(c echo.Context) error {return c.String(http.StatusOK, "Hello, World!")})e.GET("/users/:id", getUserHandler)e.POST("/users", createUserHandler)e.Logger.Fatal(e.Start(":8080"))}Add the middleware to your existing
echo.Echoinstance:package mainimport ("log""github.com/labstack/echo/v4""github.com/last9/go-agent"echoagent "github.com/last9/go-agent/instrumentation/echo")func main() {if err := agent.Start(); err != nil {log.Fatalf("Failed to start agent: %v", err)}defer agent.Shutdown()e := echo.New()// Add instrumentation middleware to existing instancee.Use(echoagent.Middleware())e.GET("/users/:id", getUserHandler)e.Logger.Fatal(e.Start(":8080"))}
Database Instrumentation
Use the agent’s database integration for automatic SQL query tracing. Supported drivers: PostgreSQL, MySQL, SQLite.
import "github.com/last9/go-agent/integrations/database"
db, err := database.Open(database.Config{ DriverName: "postgres", DSN: "postgres://user:pass@localhost/mydb", DatabaseName: "mydb",})if err != nil { log.Fatal(err)}defer db.Close()
// Use db normally — all queries are automatically tracedfunc getUserHandler(c echo.Context) error { rows, err := db.QueryContext(c.Request().Context(), "SELECT id, name FROM users WHERE id = $1", c.Param("id")) // ...}The agent automatically extracts server.address, server.port, db.user, and db.name from the DSN and attaches them to every span.
Redis Instrumentation
import redisagent "github.com/last9/go-agent/integrations/redis"
// Drop-in replacement for redis.NewClient()rdb := redisagent.NewClient(&redis.Options{ Addr: "localhost:6379",})
func cacheHandler(c echo.Context) error { val, err := rdb.Get(c.Request().Context(), "key").Result() // ...}HTTP Client Instrumentation
For outgoing requests with automatic traceparent propagation:
import httpagent "github.com/last9/go-agent/integrations/http"
client := httpagent.NewClient(&http.Client{ Timeout: 10 * time.Second,})
func proxyHandler(c echo.Context) error { req, err := http.NewRequestWithContext(c.Request().Context(), "GET", "https://upstream.example.com/api", nil) if err != nil { return err } resp, err := client.Do(req) // ...}What Gets Traced Automatically
| Signal | What’s captured |
|---|---|
| Traces | Every HTTP request: method, route pattern, status code, latency |
| Traces | Database queries: SQL statement, db system, server address/port |
| Traces | Redis commands: command name, key |
| Traces | Outbound HTTP: method, URL, status code |
| Metrics | Runtime: memory, GC pause, goroutine count |
| Metrics | HTTP: request duration, request/response sizes, active connections |
| Metrics | Database: connection pool usage, idle, wait time |
Kubernetes Deployment
apiVersion: apps/v1kind: Deploymentmetadata: name: echo-appspec: template: spec: containers: - name: echo-app image: your-registry/echo-app:latest env: - name: OTEL_SERVICE_NAME value: "echo-app" - name: OTEL_EXPORTER_OTLP_ENDPOINT valueFrom: secretKeyRef: name: last9-credentials key: endpoint - name: OTEL_EXPORTER_OTLP_HEADERS valueFrom: secretKeyRef: name: last9-credentials key: auth-header - name: OTEL_RESOURCE_ATTRIBUTES value: "deployment.environment=production"View Traces and Metrics
After running your application, navigate to Trace Explorer and Metrics Explorer in Last9 to view your telemetry data.