El SDK de C# (sdk/csharp/Ledger.Sdk) cubre la API manual Record. Las aplicaciones .NET instrumentadas con OTel deberían apuntar su exportador ya existente al receptor OTLP del ledger (/v1/otlp/v1/traces) en lugar de recurrir a un procesador de spans aquí.
Aún no está publicado en NuGet. Por ahora, referencie el proyecto directamente:
dotnet add reference <path-to-repo>/sdk/csharp/Ledger.Sdk/Ledger.Sdk.csproj
using Ledger.Sdk;
var ledger = new LedgerClient(
apiUrl: "http://127.0.0.1:4010",
ingestKey: ingestKey,
agentId: "urn:agent:research-assistant"
);
ledger.SetTrigger("human", "person@example.com");
var started = DateTimeOffset.UtcNow.AddSeconds(-1);
var ended = DateTimeOffset.UtcNow;
var spanId = ledger.Record(new RecordInput
{
ActionType = "llm_call",
Provider = "anthropic",
Model = "claude-fable-5",
StartedAt = started,
EndedAt = ended,
Status = "success",
Usage = new Usage(TokensIn: 420, TokensOut: 180),
Payloads = new[] { new Payload("response", Content: "The policy provides that…") },
});
ledger.Flush();
Record nunca lanza una excepción dentro de la aplicación anfitriona — los fallos van a ledger.OnError en su lugar. Trigger, Payload, Retrieval, ContextRef y Usage son todos records de C#, así que son inmutables y admiten expresiones with.
Establezca RecordInput.ParentRef (y HasParentRef = true) para citar el span que causó este evento — omita ambos para recurrir a la atribución ambiental/por defecto.
Flush() entrega los eventos en buffer y es seguro llamarlo con un temporizador o antes del apagado. La entrega es al-menos-una-vez — el servidor deduplica por id de span.