Grafana Cloud

Instrument .NET agents

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

Before you begin

  • A Grafana Cloud stack with Agent Observability enabled.
  • .NET 8 or later.
  • Your Agent Observability generation export endpoint URL.
  • A Cloud Access Policy Token. Refer to Collect credentials from Grafana Cloud for step-by-step instructions.

Install the SDK

Bash
dotnet add package Grafana.Agento11y

Provider helpers are in separate packages:

Bash
dotnet add package Grafana.Agento11y.OpenAI
dotnet add package Grafana.Agento11y.Anthropic
dotnet add package Grafana.Agento11y.Gemini

Capture a generation

csharp
var client = new Agento11yClient(new Agento11yClientConfig
{
    GenerationExport = new GenerationExportConfig
    {
        Protocol = GenerationExportProtocol.Http,
        Endpoint = "<AGENTO11Y_ENDPOINT>",
        Auth = new AuthConfig
        {
            Mode = ExportAuthMode.Tenant,
            TenantId = "<TENANT_ID>",
        },
    },
});

// Use provider helpers for automatic capture, for example with OpenAI:
var response = await OpenAIRecorder.CreateResponseAsync(
    client,
    openAIClient,
    inputItems,
    options: new OpenAIAgento11yOptions
    {
        ConversationId = "conv-1",
        AgentName = "my-agent",
    }
);

await client.ShutdownAsync(CancellationToken.None);

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.

csharp
var client = new Agento11yClient();

Configure authentication in code

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

csharp
Auth = new AuthConfig
{
    Mode = ExportAuthMode.Basic,
    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 for Grafana Cloud OTLP options and SDK configuration 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