Logging

Langfuse

Langfuse can be used with Superagent to enable detailed production traces and a granular view on quality, cost and latency.

Website - langfuse.com


GitHub - langfuse/langfuse

Setting up Langfuse with Docker

For quickly trying out langfuse with Superagent, a basic docker compose example is provided in the folder libs/.docker/external/observabillity/langfuse/ For a production setup refer to the official documentation on self hosting Langfuse.


Run langfuse with docker compose

The following setup is provided based on the docker compose documentation from langfuse.

  1. cd into the langfuse example folder

    $cd libs/.docker/external/observabillity/langfuse/
  2. Copy the .env.example file into a .env file

    $cp .env.example .env
  3. For quickly trying out Langfuse you can keep the default environment variables, though it is advised to review them and change the NEXTAUTH_SECRET and SALT to a more secure secret and a salt.

  4. Start Langfuse with docker compose using the provided run.sh script in the same folder.

    $./run.sh
  5. Access langfuse in the browser once the service is up.

    http://localhost:3100 or http://langfuse-server:3100 if you have added the following to your hosts file.

    $# hosts file
    >127.0.0.1 langfuse-server
  6. Sign up for an account using any credentials.

  7. Create a project named superagent

  8. Under settings and API Keys - create a new API Key, copy the Public Key and Secret Key.

  9. Enter the values in the superagent docker .env file located at libs/.docker/.env

    $# libs/.docker/.env
    >LANGFUSE_PUBLIC_KEY=<Public key e.g pk-lf-...>
    >LANGFUSE_SECRET_KEY=<Secret Key e.g sk-lf-...>
    >LANGFUSE_HOST=http://langfuse-server:3100

Langfuse container logs

$docker logs langfuse-server -f

Stop Langfuse

Use the provided stop.sh script to stop running services for lanfguse

$# libs/.docker/external/observabillity/langfuse
>./stop.sh

Uninstall Langfuse

Use the provided uninstall.sh script to remove running services for lanfguse

$# libs/.docker/external/observabillity/langfuse
>./uninstall.sh

Setting up Langfuse Cloud

Alternatively you can use the cloud hosted version of Langfuse.

  1. Sign up for an account here https://cloud.langfuse.com/

  2. Setup a project named superagent

  3. Under settings and API Keys - create a new API Key, copy the Public Key and Secret Key.

  4. Enter the values in the superagent docker .env file

    $# libs/.docker/.env
    >LANGFUSE_PUBLIC_KEY=pk-lf-...
    >LANGFUSE_SECRET_KEY=sk-lf-...
    >LANGFUSE_HOST=https://cloud.langfuse.com