> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Observability with Langfuse

## Observability with Langfuse

[Langfuse](https://langfuse.com/) is an open-source observability and analytics platform for LLM-powered applications. It collects traces, generations, and custom metrics so that you can debug, evaluate, and monitor your AI features in production.

## Integration inside Cognee

Cognee ships with Langfuse support as an optional dependency. The integration is intentionally lightweight and consists of just a few lines of code. Anywhere in the codebase where we want observability we add:

```python theme={null}
from cognee.modules.observability.get_observe import get_observe
observe = get_observe()

@observe(as_type="generation")  # optional label
async def acreate_structured_output(...):
    ...
```

> The decorator is a thin wrapper around Langfuse and automatically creates a **span** every time the function is executed.

The data is sent to the Langfuse backend specified via environment variables and can be inspected in the Langfuse UI.

## Quick Start

### 1. Install cognee with monitoring support

Langfuse is included as part of cognee's `monitoring` optional dependencies. You need to install cognee with the monitoring extra:

```bash theme={null}
pip install 'cognee[monitoring]'
```

<Note>
  Cognee currently supports `langfuse>=2.32.0,<3`.
</Note>

**Running from the cognee source repository?**

If you're developing with the cognee core repo, run the following from the project root on the main branch:

```bash theme={null}
uv sync --all-extras
```

This will install all optional dependencies, including monitoring/Langfuse support.

### 2. Create a Langfuse project

Create a project at [Langfuse Cloud](https://cloud.langfuse.com/) and copy the *public* and *secret* keys.

### 3. Configure environment variables

Export the following environment variables (for example in your `.env` file):

```
LANGFUSE_PUBLIC_KEY=<your public key>
LANGFUSE_SECRET_KEY=<your secret key>
LANGFUSE_HOST=https://cloud.langfuse.com
```

`BaseConfig` reads these values on startup, so nothing else is required. Start Cognee as usual and open the Langfuse UI – traces will appear in real time.

### 4. Run your regular Cognee workflows

```python theme={null}
import cognee
import asyncio
from cognee.modules.observability.get_observe import get_observe

observe = get_observe()

@observe(name="simple_example_run", as_type="example")
async def main():
    await cognee.remember("Natural language processing (NLP) is ...")
    results = await cognee.recall(query_text="Tell me about NLP")
    for r in results:
        print(r)

asyncio.run(main())
```

## Adding your own spans

You can instrument **any** function in your codebase:

```python theme={null}
from cognee.modules.observability.get_observe import get_observe
observe = get_observe()

@observe(as_type="my_tool", metadata={"foo": "bar"})
def my_helper(arg1, arg2):
    ...
```

You can pass the same keyword arguments that Langfuse's `observe()` decorator accepts. With **Langfuse v2** (`cognee[monitoring]` pins `langfuse>=2.32.0,<3`), common options include:

| Kwarg            | Description                                            |
| ---------------- | ------------------------------------------------------ |
| `name`           | Override the span name (defaults to the function name) |
| `as_type`        | Span type label, e.g. `"generation"`                   |
| `capture_input`  | Whether to capture function arguments                  |
| `capture_output` | Whether to capture the return value                    |
| `metadata`       | Arbitrary dict attached to the span                    |

<Info>
  Some integrations use `@observe(workflow=True)`, but that is not part of Cognee's built-in Langfuse integration. Cognee passes decorator kwargs through to Langfuse as-is, so unsupported arguments will fail at runtime.

  ```
  TypeError: LangfuseDecorator.observe() got an unexpected keyword argument 'workflow'
  ```

  If you see this error, remove `workflow=True` and use only the arguments supported by your installed Langfuse SDK version.
</Info>

See the [Langfuse Python SDK docs](https://langfuse.com/docs/sdk/python) for the full reference.

## OpenTelemetry tracing

Cognee also ships a standalone OpenTelemetry tracing layer that works independently of Langfuse and can export spans to Grafana, Jaeger, Dash0, and any other OTLP-compatible backend. See the [OpenTelemetry Tracing](/integrations/opentelemetry-tracing) page for setup details.

***

Join [Langfuse](https://discord.langfuse.com/) and [cognee](https://discord.gg/cqF6RhDYWz) communities on Discord for any questions.
