Iris
Instrument Iris Go applications with the Last9 Go Agent for automatic HTTP request tracing and metrics
Use the Last9 Go Agent to instrument your Iris application with automatic tracing and metrics. The agent implements the OTel propagation API for Iris natively — full OTel compliance with minimal code changes.
Prerequisites
- Go 1.22 or higher
- Iris v12 (
github.com/kataras/iris/v12) - 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-iris-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
iris.New()withirisagent.New()— it returns an*iris.Applicationwith the tracing middleware already attached:package mainimport ("log""github.com/kataras/iris/v12"agent "github.com/last9/go-agent"irisagent "github.com/last9/go-agent/instrumentation/iris")func main() {if err := agent.Start(); err != nil {log.Fatalf("failed to start agent: %v", err)}defer agent.Shutdown()app := irisagent.New() // drop-in for iris.New()app.Get("/users", getUsers)app.Get("/users/{id}", getUser)app.Listen(":8080")}Add the middleware to your existing Iris application:
package mainimport ("log""github.com/kataras/iris/v12"agent "github.com/last9/go-agent"irisagent "github.com/last9/go-agent/instrumentation/iris")func main() {if err := agent.Start(); err != nil {log.Fatalf("failed to start agent: %v", err)}defer agent.Shutdown()app := iris.New()app.Use(irisagent.Middleware())app.Get("/users", getUsers)app.Listen(":8080")}
Database Instrumentation
Use the agent’s database integration for automatic SQL query tracing. Supported drivers: PostgreSQL, MySQL, SQLite.
import ( "log"
"github.com/last9/go-agent/integrations/database")
var db *sql.DB
func init() { var err error db, err = database.Open(database.Config{ DriverName: "postgres", DSN: "postgres://user:pass@localhost/mydb", DatabaseName: "mydb", }) if err != nil { log.Fatal(err) }}
// Pass ctx.Request().Context() to propagate the tracefunc getUser(ctx iris.Context) { rows, err := db.QueryContext(ctx.Request().Context(), "SELECT id, name FROM users WHERE id = $1", ctx.Params().Get("id")) // ...}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 getFromCache(ctx iris.Context) { val, err := rdb.Get(ctx.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{})
func callUpstream(ctx iris.Context) { req, _ := http.NewRequestWithContext(ctx.Request().Context(), "GET", "https://api.example.com/data", nil) 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 |
View Traces and Metrics
After running your application, navigate to Trace Explorer and Metrics Explorer in Last9 to view your telemetry data.
Troubleshooting
Please get in touch with us on Discord or Email if you have any questions.