Azure-Samples / langfuse-on-azure

An easy way to deploy the Langfuse observability platform to Azure Container Apps with Entra authentication.
MIT License
39 stars 3 forks source link

name: Langfuse on Azure description: Deploy Langfuse to Azure Container Apps using the Azure Developer CLI. languages:

Langfuse on Azure

Use the Azure Developer CLI to deploy Langfuse to Azure Container Apps with PostgreSQL Flexible server.

Langfuse is a platform for LLM observability and evaluation. They provide an open-source SDK and containerized web application to receive the SDK's data. This project deploys the Langfuse web application to Azure Container Apps, and uses PostgreSQL to store the data. It also includes a script to set up Entra-based authentication for the web app. Once you have deployed Langfuse, you can integrate the SDK into your LLM applications according to the Langfuse documentation and start sending data to the web app.

From a deployed Generations tab in Langfuse:

Screenshot of Langfuse Generations tabs

Table of contents:

Opening this project

You have a few options for setting up this project. The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up locally if desired.

GitHub Codespaces

You can run this repo virtually by using GitHub Codespaces, which will open a web-based VS Code in your browser:

Open in GitHub Codespaces

Once the codespace opens (this may take several minutes), open a terminal window.

VS Code Dev Containers

A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:

  1. Start Docker Desktop (install it if not already installed)
  2. Open the project: Open in Dev Containers
  3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.

Local environment

  1. Install the required tools:

  2. Create a new folder and switch to it in the terminal.

  3. Run this command to download the project code:

    azd init -t langfuse-on-azure

    Note that this command will initialize a git repository, so you do not need to clone this repository.

  4. Create a Python virtual environment and install the required packages:

    pip install -r requirements.txt
  5. Open a terminal window inside the project folder.

Deploying to Azure

Follow these steps to deploy Langfuse to Azure:

  1. Login to your Azure account:

    azd auth login
  2. Create a new azd environment:

    azd env new

    Enter a name that will be used for the resource group. This will create a new folder in the .azure folder, and set it as the active environment for any calls to azd going forward.

  3. (Optional) By default, the deployed Azure Container App will use the Langfuse authentication system, meaning anyone with routable network access to the web app can attempt to login to it. To enable Entra-based authentication, set the AZURE_USE_AUTHENTICATION environment variable to true:

    azd env set AZURE_USE_AUTHENTICATION true

    Then set the AZURE_AUTH_TENANT_ID environment variable to your tenant ID:

    azd env set AZURE_AUTH_TENANT_ID your-tenant-id
  4. Run this command to provision all the resources:

    azd provision

    This will create a new resource group, and create the Azure Container App and PostgreSQL Flexible server inside that group. If you enabled authentication, it will use the auth_init.sh and auth_update.sh hooks to set up the necessary resources for Entra-based authentication, and pass the necessary environment variables to the Azure Container App.

  5. Once the deployment is complete, you will see the URL for the Azure Container App in the output. You can open this URL in your browser to see the Langfuse web app.

Disclaimer

Langfuse is an external project and is not affiliated with Microsoft.