OpenInference.LLM.Telemetry
0.1.0-beta.1
See the version list below for details.
dotnet add package OpenInference.LLM.Telemetry --version 0.1.0-beta.1
NuGet\Install-Package OpenInference.LLM.Telemetry -Version 0.1.0-beta.1
<PackageReference Include="OpenInference.LLM.Telemetry" Version="0.1.0-beta.1" />
<PackageVersion Include="OpenInference.LLM.Telemetry" Version="0.1.0-beta.1" />
<PackageReference Include="OpenInference.LLM.Telemetry" />
paket add OpenInference.LLM.Telemetry --version 0.1.0-beta.1
#r "nuget: OpenInference.LLM.Telemetry, 0.1.0-beta.1"
#:package OpenInference.LLM.Telemetry@0.1.0-beta.1
#addin nuget:?package=OpenInference.LLM.Telemetry&version=0.1.0-beta.1&prerelease
#tool nuget:?package=OpenInference.LLM.Telemetry&version=0.1.0-beta.1&prerelease
OpenInference.LLM.Telemetry
A comprehensive OpenTelemetry-based library for tracking and monitoring Large Language Model (LLM) operations in .NET applications according to the OpenInference semantic convention standard.
Features
- ✅ OpenInference compliant LLM telemetry instrumentation
- ✅ Seamless integration with OpenTelemetry
- ✅ Support for Azure OpenAI and OpenAI APIs
- ✅ Multiple integration patterns:
- HTTP client handlers
- Direct instrumentation
- Dependency Injection
- Convenience methods for popular LLM operations
- ✅ Compatible with:
- Azure Functions
- ASP.NET Core
- Any .NET application using OpenTelemetry
Architecture Overview
The library consists of several components that work together to provide comprehensive LLM telemetry:
┌─────────────────────────────────────────────────────────────────┐
│ Your .NET Application │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────────┐ ┌───────────────────────────────┐ │
│ │ │ │ │ │
│ │ LLM API Client │◀─────▶│ LLMTelemetryHandler │ │
│ │ │ │ (Automatic HTTP Telemetry) │ │
│ └───────────────────┘ └───────────────────────────────┘ │
│ │ │ │
│ ▼ │ │
│ ┌───────────────────┐ │ │
│ │ │ │ │
│ │ Your LLM Logic │ ▼ │
│ │ │ ┌───────────────────────────────┐ │
│ └───────────────────┘ │ │ │
│ │ │ LLMTelemetry │ │
│ │ │ (Core Telemetry Methods) │ │
│ ▼ │ │ │
│ ┌───────────────────┐ └───────────────────────────────┘ │
│ │ Manual │ │ │
│ │ Instrumentation │─────────────────────┘ │
│ │ (Optional) │ │
│ └───────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ OpenTelemetry │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────────┐ ┌───────────────────────────────┐ │
│ │ OpenTelemetry │ │ │ │
│ │ TracerProvider │◀───────│ LlmInstrumentation │ │
│ │ │ │ │ │
│ └───────────────────┘ └───────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ OpenTelemetry Exporters (Console, OTLP, Azure Monitor) │ │
│ │ │ │
│ └───────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Components:
- LLMTelemetryHandler: Intercepts HTTP requests to LLM APIs and automatically adds telemetry.
- LLMTelemetry: Core class with methods for creating and managing telemetry activities.
- LlmInstrumentation: Integration with OpenTelemetry for standardized tracing.
- Manual Instrumentation: Optional direct instrumentation for custom scenarios.
This architecture allows for flexible integration options while ensuring consistent telemetry data.
Installation
dotnet add package OpenInference.LLM.Telemetry
Quick Start
Basic Setup
Add OpenInference LLM telemetry to your application:
// Program.cs or Startup.cs
// Register with dependency injection
builder.Services.AddOpenInferenceLlmTelemetry(options => {
options.EmitTextContent = true; // Include prompt & response text
options.MaxTextLength = 1000; // Truncate long text to limit storage
options.SanitizeSensitiveInfo = true; // Attempt to redact sensitive info
});
// Configure OpenTelemetry
builder.Services.AddOpenTelemetryWithLlmTracing(
serviceName: "MyService",
builder => builder
.AddConsoleExporter()
.AddOtlpExporter());
Integration Methods
HttpClient Integration
// Add LLM telemetry to your HttpClient
services.AddHttpClient("AzureOpenAI", client => {
client.BaseAddress = new Uri("https://your-resource.openai.azure.com/");
client.DefaultRequestHeaders.Add("api-key", "your-api-key");
})
.AddLLMTelemetry(
defaultModelName: "gpt-4",
provider: "azure");
Direct Instrumentation
// Use the core LLMTelemetry class directly
using var activity = LLMTelemetry.StartLLMActivity(
modelName: "gpt-4",
prompt: "Explain quantum computing",
taskType: "chat",
provider: "openai");
try
{
// Perform your LLM operation
var response = await client.GetChatCompletionsAsync(options);
LLMTelemetry.EndLLMActivity(
activity: activity,
response: response.Value.Choices[0].Message.Content,
isSuccess: true,
latencyMs: stopwatch.ElapsedMilliseconds);
}
catch (Exception ex)
{
LLMTelemetry.RecordException(activity, ex);
throw;
}
Azure OpenAI Integration
// Track chat completions from Azure OpenAI
var stopwatch = Stopwatch.StartNew();
var result = await client.GetChatCompletionsAsync(options);
stopwatch.Stop();
AzureOpenAIAdapter.TrackChatCompletion(
options: options,
result: result.Value,
modelName: "gpt-4",
latencyMs: stopwatch.ElapsedMilliseconds);
Configuration Options
services.AddOpenInferenceLlmTelemetry(options => {
// Whether to include prompt and response text in telemetry
options.EmitTextContent = true;
// Maximum length of text to include (truncated beyond this)
options.MaxTextLength = 1000;
// Whether to emit latency metrics
options.EmitLatencyMetrics = true;
// Whether to include model name information
options.RecordModelName = true;
// Whether to record token usage information
options.RecordTokenUsage = true;
// Whether to attempt to sanitize sensitive information in prompts
options.SanitizeSensitiveInfo = false;
});
Advanced Usage
For more advanced usage scenarios and examples, see USAGE.md.
OpenInference Semantic Conventions
This library follows the OpenInference semantic conventions for LLM telemetry. Key attributes captured include:
llm.request: The prompt textllm.response: The model's responsellm.request_type: The type of request (chat, completion, etc)llm.model: The model namellm.model_provider: The provider name (azure, openai)llm.success: Whether the operation succeededllm.latency_ms: Operation latency in millisecondsllm.token_count.prompt: Number of tokens in promptllm.token_count.completion: Number of tokens in completionllm.token_count.total: Total token count
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Azure.AI.OpenAI (>= 1.0.0-beta.17)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- OpenTelemetry (>= 1.7.0)
- OpenTelemetry.Api (>= 1.7.0)
- OpenTelemetry.Extensions.Hosting (>= 1.7.0)
- System.Diagnostics.DiagnosticSource (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 0.1.0-beta.8 | 178 | 5/18/2025 | |
| 0.1.0-beta.6 | 269 | 5/15/2025 | |
| 0.1.0-beta.5 | 268 | 5/12/2025 | |
| 0.1.0-beta.4 | 190 | 5/8/2025 | |
| 0.1.0-beta.3 | 187 | 5/8/2025 | |
| 0.1.0-beta.2 | 192 | 5/6/2025 | |
| 0.1.0-beta.1 | 207 | 4/28/2025 |