zborek.LangfuseDotnet 0.2.1

dotnet add package zborek.LangfuseDotnet --version 0.2.1
                    
NuGet\Install-Package zborek.LangfuseDotnet -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="zborek.LangfuseDotnet" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="zborek.LangfuseDotnet" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="zborek.LangfuseDotnet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add zborek.LangfuseDotnet --version 0.2.1
                    
#r "nuget: zborek.LangfuseDotnet, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package zborek.LangfuseDotnet@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=zborek.LangfuseDotnet&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=zborek.LangfuseDotnet&version=0.2.1
                    
Install as a Cake Tool

WORK IN PROGRESS

LangfuseDotnet

<a href="https://www.nuget.org/packages/zborek.LangfuseDotnet/"> <img src="https://img.shields.io/nuget/v/zborek.LangfuseDotnet" alt="NuGet"> </a>

A .NET client library for Langfuse - an open-source observability and analytics platform for LLM applications. This library enables you to track, monitor, and analyze your AI application performance and behavior.

Features

  • Create and manage traces, spans, events, and generations
  • Automatic background ingestion of observability data
  • Integration with dependency injection
  • Support for both .NET 8.0 and 9.0
  • Customizable configuration options

Installation

Install the package via NuGet:

dotnet add package zborek.LangfuseDotnet

Getting Started

Configuration

Add Langfuse configuration to your appsettings.json:

{
  "Langfuse": {
    "PublicKey": "YOUR_PUBLIC_KEY",
    "SecretKey": "YOUR_SECRET_KEY",
    "SendLogs": true
  }
}

Registration with DI

// In Program.cs or Startup.cs
builder.Services.AddLangfuse(builder.Configuration);

Usage in Your Application

Inject LangfuseTrace into your service:

public class MyService
{
    private readonly LangfuseTrace _langfuseTrace;

    public MyService(LangfuseTrace langfuseTrace)
    {
        _langfuseTrace = langfuseTrace;
    }
    
    public async Task ProcessAsync(string input)
    {
        _langfuseTrace.Trace.Body.Input = input;
        
        // Create spans to track operations
        using var dataSpan = _langfuseTrace.CreateSpan("GetData");
        var data = await GetDataAsync(input);
        dataSpan.SetOutput(data);
        
        // Track LLM generations
        using var generationSpan = _langfuseTrace.CreateGeneration("LLMProcessing", 
            input: $"Process: {input} with {data}", 
            output: null);
        
        var result = await CallLLMAsync(input, data);
        generationSpan.SetOutput(result);
        
        // Record events
        using var _ = _langfuseTrace.CreateEvent("ProcessingComplete", 
            input: input, 
            output: result);
        
        // Send data to Langfuse
        await _langfuseTrace.IngestAsync();
        
        return result;
    }
}

Core Concepts

  • Trace: A complete workflow or user session
  • Span: A logical operation or step within a trace
  • Generation: A specific LLM call or generation
  • Event: A discrete occurrence within your application

Complete Example

See the Examples/Langfuse.Example.WebApi directory for a complete working example showing integration with OpenAI.

API Endpoints in Example Project

  • POST /chat: Processes a chat request using direct service implementation
  • POST /chatDi: Processes a chat request using dependency injection

Troubleshooting

  • Missing ingestion data: Ensure SendLogs is set to true in your configuration
  • Authentication errors: Verify your Langfuse API keys
  • Data not appearing: Check if IngestAsync() is called after operations

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Additional Resources

Product 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.1 212 6/8/2025
0.2.0 320 3/3/2025
0.1.0 167 2/16/2025
0.0.1 127 2/7/2025