Skip to content

Commit

Permalink
rework
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrichwilken committed Jan 22, 2025
1 parent 46a816c commit 4b0dc95
Showing 1 changed file with 104 additions and 33 deletions.
137 changes: 104 additions & 33 deletions docs/langfuse.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,119 @@
# LangFuse
- [Official Website](https://langfuse.com/)
- [Official Docs](https://langfuse.com/docs)
## Local deployment

## Setup
### Run a local instance of LangFuse
First, in the base directory of your local copy of the `Kyma-Companion` repository open or create the `.env` file:
```bash
vi .env
### Set up Redis

A local instance of LangFuse will bring it's own instance of `Redis` with some basic authentication setup. The password defaults to `myredissecret` (if you do not specify the env var `REDIS_AUTH`) and LangFuse will automatically use the database number `0` of that Redis instance (remember that it comes by default with 16 databases, 0 to 15).
If you also run a local instance of `Redis` for the `Companion`, you have two options.
a) You let the `Companion` use the Redis instance that comes with Langfuse and addressing database `1` by adding these lines in your `config/config.json`:

```json
"REDIS_PASSWORD": "myredissecret",
"REDIS_DB_NUMBER": "1",
```
and paste the following:

b) Setup your `Redis` instance which you usually use directly with the `Companion` to run on a different port like `6380` (default port for redis is 6379)

```
LANGFUSE_SECRET_KEY=
LANGFUSE_PUBLIC_KEY=
LANGFUSE_HOST=http://localhost:3000
docker run -d --name redis -p 6380:6379 redis
```
Keep this open, we will need it in a minute.

To run LangFuse locally you need to download the source code from github.com. These are the required steps:
Then you set your `config/config.json` to:

```json
"REDIS_PORT": "6380",
```

### Deploy Langfuse locally

Get a local copy of the LangFuse repository:

```bash
# The directory where we will clone the source code to; change as you need.
export LANGFUSE_DIR=~/src/github.com/langfuse
# Create the parent directory.
mkdir -p $LANGFUSE_DIR
# Change to the newly created directory.
cd $LANGFUSE_DIR
# Clone the repository.
git clone https://github.com/langfuse/langfuse.git
# Enter the directory of the repository.
git clone https://github.com/langfuse/langfuse.gitcd langfuse
cd langfuse
# Start the database and LangFuse server.
docker compose up --wait
# Create a new account.
open http://localhost:3000/auth/sign-up
```
Hit the `+ New project` button, give your project a name, and hit `Create`. On the next page you will find the values for `LANGFUSE_SECRET_KEY` and `LANGFUSE_PUBLIC_KEY`; copy them into your `.env` file.

If you already have a local copy of the LangFuse repository, don't forget to `pull` the latest changes, since it gets frequently updated. Then just run:
Start the application:

```bash
docker compose up
```

Open the web interface:

```bash
git pull
docker compose up --wait
open http://localhost:3000/auth/sign-up
```
from the directory of you local copy.

You can now watch the traces of the `Kyma-Companion` from http://localhost:3000.
Create an account, then hit the `+ New Organization` button. Give your organization a name, hit `Next` in the `Invite Members` page, find a name for you project an hit `Create`.
On the next page, hit the `API Keys` menu point, then hit the `+ Create new API keys` button. Copy the `Secret Key`, `Secret Key` and `Host` and paste them as values in to your `kyma-companion`'s `config/config.json` for your `LANGFUSE_HOST`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_PUBLIC_KEY` keys:

```json
...
"LANGFUSE_HOST": "https://localhost:3000",
"LANGFUSE_SECRET_KEY": "<your secret key>",
"LANGFUSE_PUBLIC_KEY": "<your public key>",
```

## Deploy on Kubernetes

### For development purpose

For a minimal setup run:

```shell
kubectl create ns langfuse
helm repo add langfuse https://langfuse.github.io/langfuse-k8s
helm repo update
helm install langfuse langfuse/langfuse --namespace langfuse
```

to expose the `langfuse-web` service outside we need an `apirule`. To find out what your `host` is run:

```shell
kubectl get gateway kyma-gateway -n kyma-system -o=jsonpath='{.spec.servers[0].hosts[0]}'
```

Now past your `host` into this manifest:

```yaml
apiVersion: gateway.kyma-project.io/v1beta1
kind: APIRule
metadata:
labels:
app.kubernetes.io/name: langfuse
name: langfuse
namespace: langfuse
spec:
gateway: kyma-system/kyma-gateway
host: langfuse.<YOUR HOST>
rules:
- accessStrategies:
- handler: no_auth
methods:
- GET
- POST
- PUT
- OPTIONS
path: /.*
service:
name: langfuse-web
port: 3000
```
and apply it to the cluster.
Open the web interface:
```bash
open http://langfuse.<YOUR HOST>:3000/auth/sign-up
```

Create an account, then hit the `+ New Organization` button. Give your organization a name, hit `Next` in the `Invite Members` page, find a name for you project an hit `Create`.
On the next page, hit the `API Keys` menu point, then hit the `+ Create new API keys` button. Copy the `Secret Key`, `Secret Key` and `Host` and paste them as values in to your `kyma-companion`'s `config/config.json` for your `LANGFUSE_HOST`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_PUBLIC_KEY` keys:

```json
...
"LANGFUSE_HOST": "https://langfuse.<YOUR HOST>:3000",
"LANGFUSE_SECRET_KEY": "<your secret key>",
"LANGFUSE_PUBLIC_KEY": "<your public key>",
```

0 comments on commit 4b0dc95

Please sign in to comment.