---
title: "Instrument Go agents | Grafana Cloud documentation"
description: "Install the Agent Observability Go SDK and capture your first generation from a Go agent."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Instrument Go agents

This guide shows you how to install the Agent Observability Go SDK, instrument an LLM call, and verify that generation data reaches Agent Observability.

## Before you begin

- A Grafana Cloud stack with Agent Observability enabled.
- Go 1.23 or later.
- Your Agent Observability generation export endpoint URL.
- A Cloud Access Policy Token. Refer to [Collect credentials from Grafana Cloud](/docs/grafana-cloud/observe-and-act/agent-observability/get-started/grafana-cloud/#collect-credentials-from-grafana-cloud) for step-by-step instructions.

## Install the SDK

Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```bash
go get github.com/grafana/agento11y/go
```

## Capture a generation

Go ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```go
package main

import (
	"context"

	"github.com/grafana/agento11y/go/agento11y"
)

func main() {
	cfg := agento11y.DefaultConfig()
	cfg.GenerationExport.Protocol = agento11y.GenerationExportProtocolHTTP
	cfg.GenerationExport.Endpoint = "<AGENTO11Y_ENDPOINT>"
	cfg.GenerationExport.Auth = agento11y.AuthConfig{
		Mode:     agento11y.ExportAuthModeTenant,
		TenantID: "<TENANT_ID>",
	}

	client := agento11y.NewClient(cfg)
	defer func() { _ = client.Shutdown(context.Background()) }()

	ctx, rec := client.StartGeneration(context.Background(), agento11y.GenerationStart{
		ConversationID: "conv-1",
		Model:          agento11y.ModelRef{Provider: "openai", Name: "gpt-4o"},
	})
	defer rec.End()

	_ = ctx // pass ctx to downstream calls for trace propagation

	rec.SetResult(agento11y.Generation{
		Output: []agento11y.Message{agento11y.AssistantTextMessage("Hello")},
	}, nil)
}
```

Replace *AGENTO11Y\_ENDPOINT* and *TENANT\_ID* with your values.

### Use environment variables instead

If you set `AGENTO11Y_ENDPOINT`, `AGENTO11Y_PROTOCOL`, `AGENTO11Y_AUTH_MODE`, `AGENTO11Y_AUTH_TENANT_ID`, and `AGENTO11Y_AUTH_TOKEN`, the SDK reads them at client construction. Refer to [Configure your SDK](/docs/grafana-cloud/observe-and-act/agent-observability/get-started/grafana-cloud/#configure-your-sdk).

Go ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```go
client := agento11y.NewClient(agento11y.Config{})
```

## Use a provider helper

Provider helpers wrap LLM client calls to capture generations automatically. Helpers are available for OpenAI, Anthropic, and Gemini:

Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```bash
go get github.com/grafana/agento11y/go-providers/openai
go get github.com/grafana/agento11y/go-providers/anthropic
go get github.com/grafana/agento11y/go-providers/gemini
```

## Use a framework integration

A Google ADK framework integration is available:

Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```bash
go get github.com/grafana/agento11y/go-frameworks/google-adk
```

## Configure authentication in code

For Grafana Cloud, use basic auth with your Cloud Access Policy Token:

Go ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```go
cfg.GenerationExport.Auth = agento11y.AuthConfig{
	Mode:          agento11y.ExportAuthModeBasic,
	TenantID:      "<INSTANCE_ID>",
	BasicPassword: "<API_KEY>",
}
```

## Set up traces and metrics

The SDK emits OpenTelemetry spans and metrics alongside generation data. To export them, configure a `TracerProvider` and `MeterProvider` in your application before creating the client. Without this, traces and metrics are silently lost.

Refer to [Set up traces and metrics](/docs/grafana-cloud/observe-and-act/agent-observability/get-started/grafana-cloud/#set-up-traces-and-metrics) for Grafana Cloud OTLP options and [SDK configuration](/docs/grafana-cloud/observe-and-act/agent-observability/configure/sdk/#opentelemetry-setup) for setup snippets.

## Verify data

Open Agent Observability in Grafana Cloud and navigate to **Conversations**. Your generation should appear within a few seconds. Check your **Traces** and **Metrics** data sources for SDK-emitted spans and metrics.

## Next steps

- [Configure SDK options](/docs/grafana-cloud/observe-and-act/agent-observability/configure/sdk)
- [Instrument with framework integrations](/docs/grafana-cloud/observe-and-act/agent-observability/guides/instrument-agents)
