Veriproof.Sdk.Instrumentation.AutoGen
Provides AutoGenOTelAdapter, a helper that creates an agent_run root span for each workflow and wraps any IChatClient to emit individual chat_completion child spans per agent call.
Compatibility: .NET 10+, Microsoft.Extensions.AI 9.0+
Installation
dotnet add package Veriproof.Sdk.Core
dotnet add package Veriproof.Sdk.Annotations
dotnet add package Veriproof.Sdk.Instrumentation.AutoGenSetup
using OpenTelemetry.Trace;
using Veriproof.Sdk;
using Veriproof.Sdk.Instrumentation.AutoGen;
var builder = WebApplication.CreateBuilder(args);
// 1. Register the AutoGen adapter
builder.Services.AddVeriproofAutoGenInstrumentation(options =>
{
options.GenAiSystem = "autogen";
options.CaptureMessageContent = false; // opt-in: include message bodies
});
// 2. Configure VeriProof OTel exporter
builder.Services.AddOpenTelemetry()
.WithTraces(traces => traces
.AddSource("*")
.AddVeriproofTracing(options =>
{
options.ApiKey = builder.Configuration["VeriproofApiKey"]!;
options.ApplicationId = builder.Configuration["VeriproofApplicationId"]!;
})
);AutoGenAdapterOptions
| Option | Type | Default | Description |
|---|---|---|---|
TenantId | string? | null | Override tenant for this adapter |
ApplicationId | string? | null | Override application ID for this adapter |
GenAiSystem | string | "autogen" | gen_ai.system on all child spans |
CaptureMessageContent | bool | false | Include message text in span attributes (requires EnableContentCapture in exporter options) |
MaxContentLength | int | 2048 | Truncation limit for captured content |
AutoGenOTelAdapter API
Inject AutoGenOTelAdapter from DI and use it to bracket workflows and wrap IChatClient instances.
StartAgentRun
AgentRunHandle StartAgentRun(
string workflowName,
string? agentName = null,
string? sessionId = null
);Creates an agent_run span that acts as the root for all agent activity in this workflow. Dispose the handle to end the span.
using var run = adapter.StartAgentRun(
"LoanApprovalWorkflow",
agentName: "Orchestrator",
sessionId: customerId
);AgentRunHandle
| Member | Type | Description |
|---|---|---|
TraceId | string | W3C trace ID of the agent_run span |
SpanId | string | Span ID of the agent_run span |
SetTag(key, value) | AgentRunHandle | Add an OTel attribute; returns this for chaining |
SetFailed(Exception) | void | Mark the span as failed with the exception message |
Dispose() | End the agent_run span |
run
.SetTag("veriproof.transaction.id", $"loan:{applicationId}")
.SetTag("loan.applicant.id", applicantId);WrapClient
IChatClient WrapClient(
IChatClient inner,
string agentName,
string? defaultModelId = null
);Returns a decorated IChatClient that emits a child chat_completion span for each GetResponseAsync call, tagged with gen_ai.agent.name and gen_ai.request.model.
var analystClient = adapter.WrapClient(
inner: chatClient,
agentName: "LoanAnalyst",
defaultModelId: "gpt-4.1"
);
var response = await analystClient.GetResponseAsync(messages, options, ct);Multi-agent example
using Veriproof.Sdk.Annotations;
using Veriproof.Sdk.Annotations.Models;
using Veriproof.Sdk.Instrumentation.AutoGen;
public class LoanApprovalOrchestrator(
AutoGenOTelAdapter adapter,
IChatClient chatClient,
ILogger<LoanApprovalOrchestrator> logger)
{
public async Task<string> RunAsync(
string applicationId,
string applicantId,
decimal creditScore,
CancellationToken ct = default)
{
// 1. Start the agent_run span — covers the entire workflow
using var run = adapter.StartAgentRun(
"LoanApprovalWorkflow",
agentName: "Orchestrator",
sessionId: applicantId
);
run.SetTag("veriproof.transaction.id", $"loan:{applicationId}")
.SetTag("loan.application.id", applicationId)
.SetTag("loan.applicant.id", applicantId);
try
{
// 2. Wrap each agent's chat client — child spans emit automatically
var analystClient = adapter.WrapClient(
chatClient, agentName: "LoanAnalyst", defaultModelId: "gpt-4.1");
var reviewerClient = adapter.WrapClient(
chatClient, agentName: "ComplianceReviewer", defaultModelId: "gpt-4.1");
// 3. Analyst step: assess creditworthiness
var analystMessages = new[] {
new ChatMessage(ChatRole.System,
"You are a loan analyst. Assess the application and recommend APPROVE or REJECT."),
new ChatMessage(ChatRole.User,
$"Application {applicationId}: credit score {creditScore}, applicant {applicantId}")
};
var analystResponse = await analystClient.GetResponseAsync(analystMessages, ct: ct);
var analystOpinion = analystResponse.Message.Text ?? "";
// 4. Reviewer step: compliance check
var reviewMessages = new[] {
new ChatMessage(ChatRole.System,
"You are a compliance officer. Validate the analyst recommendation against policy."),
new ChatMessage(ChatRole.User,
$"Analyst recommendation: {analystOpinion}")
};
var reviewResponse = await reviewerClient.GetResponseAsync(reviewMessages, ct: ct);
var decision = reviewResponse.Message.Text ?? "REJECT";
// 5. Enrich the agent_run span with governance metadata
run.SetTag("veriproof.session.intent", "transaction")
.SetTag("veriproof.step.outcome", "success")
.SetTag("loan.decision", decision);
return decision;
}
catch (Exception ex)
{
run.SetFailed(ex);
throw;
}
}
}Span hierarchy
agent_run (LoanApprovalWorkflow / Orchestrator)
├── chat_completion gen_ai.agent.name = "LoanAnalyst"
│ gen_ai.request.model = "gpt-4.1"
│ gen_ai.usage.input_tokens = 312
│ gen_ai.usage.output_tokens = 87
│
└── chat_completion gen_ai.agent.name = "ComplianceReviewer"
gen_ai.request.model = "gpt-4.1"
gen_ai.usage.input_tokens = 198
gen_ai.usage.output_tokens = 43Adding governance annotations
Combine AgentRunHandle.SetTag with Veriproof.Sdk.Annotations Activity extension methods for full governance coverage:
using var run = adapter.StartAgentRun("LoanApprovalWorkflow");
run.SetTag("veriproof.transaction.id", $"loan:{applicationId}");
// Access the current Activity if you need typed extension methods
System.Diagnostics.Activity.Current?
.SetSessionIntent(SessionIntent.transaction)
.SetRiskLevel(RiskLevel.Medium)
.AddRiskFactor(RiskFactor.LowConfidence("Thin credit file"));Next steps
- Semantic Kernel instrumentation — automatic span capture for SK pipelines
- Veriproof.Sdk.Annotations reference — governance enums and
Activityextension methods - AutoGen multi-agent example — complete runnable application
Last updated on