Class LdAiConfigTracker
Records metrics for a single AI run.
Implements
Inherited Members
Namespace: LaunchDarkly.Sdk.Server.Ai
Assembly: LaunchDarkly.ServerSdk.Ai.dll
Syntax
public class LdAiConfigTracker : ILdAiConfigTracker
Remarks
All events a tracker emits share a runId (a UUIDv4) so LaunchDarkly can correlate
them in metrics views. See individual track methods for their specific semantics.
Call CreateTracker on the AI Config to start a new run. A
ResumptionToken preserves the runId, so events emitted by a tracker
reconstructed in another process correlate with the original tracker's runId.
Properties
| Edit this page View SourceResumptionToken
A URL-safe Base64-encoded token that can be used to reconstruct this tracker in a different process or at a later time. The token contains the runId, configKey, variationKey, and version.
Use LdAiConfigTracker.FromResumptionToken to reconstruct a tracker from this token.
Declaration
public string ResumptionToken { get; }
Property Value
| Type | Description |
|---|---|
| string |
Summary
A summary of the metrics tracked by this tracker.
Declaration
public MetricSummary Summary { get; }
Property Value
| Type | Description |
|---|---|
| MetricSummary |
Methods
| Edit this page View SourceFromResumptionToken(string, ILaunchDarklyClient, Context)
Reconstructs a tracker from a resumption token. This enables cross-process scenarios such as deferred feedback, where a tracker's runId needs to be reused in a different process or at a later time.
The reconstructed tracker will have empty model and provider names, as these are not included in the resumption token.
Declaration
public static LdAiConfigTracker FromResumptionToken(string token, ILaunchDarklyClient client, Context context)
Parameters
| Type | Name | Description |
|---|---|---|
| string | token | the resumption token obtained from ResumptionToken |
| ILaunchDarklyClient | client | the LaunchDarkly client |
| Context | context | the context to use for track events |
Returns
| Type | Description |
|---|---|
| LdAiConfigTracker | a new tracker associated with the original run |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | thrown if token or client is null |
| ArgumentException | thrown if the token is malformed or missing required fields |
TrackDuration(float)
Tracks a duration metric related to this config. For example, if a particular operation related to usage of the AI model takes 100ms, this can be tracked and made available in LaunchDarkly.
Declaration
public void TrackDuration(float durationMs)
Parameters
| Type | Name | Description |
|---|---|---|
| float | durationMs | the duration in milliseconds |
Remarks
Records at most once per Tracker; further calls are ignored.
TrackDurationOfTask<T>(Task<T>)
Tracks the duration of a task, and returns the result of the task.
If the provided task throws, then this method will also throw.
In the case the provided function throws, this function will still record the duration.
Declaration
public Task<T> TrackDurationOfTask<T>(Task<T> task)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T> | task | the task |
Returns
| Type | Description |
|---|---|
| Task<T> | the task |
Type Parameters
| Name | Description |
|---|---|
| T | type of the task's result |
TrackError()
Tracks an unsuccessful generation event related to this config.
Declaration
public void TrackError()
Remarks
Records at most once per Tracker. TrackSuccess and TrackError share state; only one of the two can record per Tracker, and subsequent calls are ignored.
TrackFeedback(Feedback)
Tracks feedback (positive or negative) related to the output of the model.
Declaration
public void TrackFeedback(Feedback feedback)
Parameters
| Type | Name | Description |
|---|---|---|
| Feedback | feedback | the feedback |
Remarks
Records at most once per Tracker; further calls are ignored.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
TrackRequest(Task<Response>)
Tracks a request to a provider. The request is a task that returns a Response, which contains information about the request such as token usage and metrics.
This function will track the duration of the operation, the token usage, and the success or error status.
If the provided function throws, then this method will also throw.
In the case the provided function throws, this function will record the duration and an error.
A failed operation will not have any token usage data.
It is the responsibility of the caller to fill in the Response object with any details that should be tracked.
Example:
var response = tracker.TrackRequest(Task.Run(() => new Response {
// 1. Make a request to the AI provider
// 2. Identify relevant statistics returned in the response
// 3. Return a Response object containing the relevant statistics
Usage = new Usage { Total = 1, Input = 1, Output = 1 },
Metrics = new Metrics { LatencyMs = 100 }
}));
If no latency statistic is explicitly returned in the Response, then the duration of the Task is automatically measured and recorded as the latency metric associated with this request.
Declaration
public Task<Response> TrackRequest(Task<Response> request)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<Response> | request | a task representing the request |
Returns
| Type | Description |
|---|---|
| Task<Response> | the task |
Remarks
Subsequent calls re-run the task but emit only metrics not already recorded on this Tracker.
Call CreateTracker on the AI Config to start a new run.
TrackSuccess()
Tracks a generation event related to this config.
Declaration
public void TrackSuccess()
Remarks
Records at most once per Tracker. TrackSuccess and TrackError share state; only one of the two can record per Tracker, and subsequent calls are ignored.
TrackTimeToFirstToken(float)
Tracks the time it takes for the first token to be generated.
Declaration
public void TrackTimeToFirstToken(float timeToFirstTokenMs)
Parameters
| Type | Name | Description |
|---|---|---|
| float | timeToFirstTokenMs | the duration in milliseconds |
Remarks
Records at most once per Tracker; further calls are ignored.
TrackTokens(Usage)
Tracks token usage related to this config.
Declaration
public void TrackTokens(Usage usage)
Parameters
| Type | Name | Description |
|---|---|---|
| Usage | usage | the token usage |
Remarks
Records at most once per Tracker; further calls are ignored.