> For the complete documentation index, see [llms.txt](https://docs.appmixer.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appmixer.com/getting-started/ai-copilot/langfuse.md). Agents can also search and read this documentation through its [MCP server](https://docs.appmixer.com/~gitbook/mcp).

# Tracing Copilot with Langfuse

Copilot can send a trace of every chat request to [Langfuse](https://langfuse.com), an LLM observability platform. Use it to see what Copilot did on a turn and why: the prompts it sent, the model's replies, each tool it called with the tool's input and output, and the token usage and latency of each step.

Tracing is off by default. It turns on when both Langfuse keys are configured, and it works with Langfuse Cloud and with a self-hosted Langfuse instance.

## Configuration

| Environment Variable          | Default                      | Description                                                                                                                                                                             |
| ----------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `COPILOT_LANGFUSE_PUBLIC_KEY` | *(unset)*                    | Public key of your Langfuse project (`pk-lf-...`).                                                                                                                                      |
| `COPILOT_LANGFUSE_SECRET_KEY` | *(unset)*                    | Secret key of your Langfuse project (`sk-lf-...`).                                                                                                                                      |
| `COPILOT_LANGFUSE_BASE_URL`   | `https://cloud.langfuse.com` | URL of the Langfuse instance. Leave it unset for Langfuse Cloud in the EU region. Set it to `https://us.cloud.langfuse.com` for the US region, or to the URL of a self-hosted instance. |

1. In Langfuse, open the project that should receive the traces and create an API key pair in its settings.
2. In the Backoffice, set `COPILOT_LANGFUSE_PUBLIC_KEY` and `COPILOT_LANGFUSE_SECRET_KEY`, plus `COPILOT_LANGFUSE_BASE_URL` if you don't use Langfuse Cloud in the EU region. On a self-managed installation you can set them as environment variables instead.
3. Send a message to Copilot. The trace appears in Langfuse a few seconds after the turn ends.

You don't need to restart anything. Copilot reads the keys on every chat request, so a new or rotated key pair takes effect on the next request. To turn tracing off, remove either key (for example `DELETE /config/COPILOT_LANGFUSE_SECRET_KEY`). Spans that are still buffered are sent before the pipeline shuts down.

Both keys must be set for tracing to work. An empty or whitespace-only value counts as unset, and the Backoffice rejects one.

{% hint style="info" %}
Copilot sends the traces from the Appmixer API nodes, so those nodes need outbound HTTPS access to the Langfuse URL. On an installation with restricted egress, allow this host before you enable tracing.
{% endhint %}

## What a trace contains

Each Copilot chat turn becomes one trace, named `copilot.chat`. It contains the whole agent run: every LLM call with its prompt and completion, every tool call with its input and output, and the token usage and latency of each step.

Copilot sets these trace attributes so you can filter and group traces:

| Langfuse field | Value                                                                                                                            |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| User ID        | ID of the Appmixer user who sent the message.                                                                                    |
| Session ID     | ID of the Copilot conversation thread, so every turn of one conversation is grouped in one Langfuse session.                     |
| Tags           | `copilot`; the provider path, `direct` or `appmixer-cloud-proxy`; and on the direct path, the LLM provider, such as `anthropic`. |
| Metadata       | `flowId`, when the conversation is about a flow.                                                                                 |

To look into a user's report, filter by their user ID, open the session for the conversation and step through the turn that went wrong.

## Data protection

{% hint style="warning" %}
The platform logs never record the content of Copilot messages, but Langfuse traces do. Point Copilot only at a Langfuse instance that is approved to hold this data.
{% endhint %}

A trace can contain:

* The user's messages and Copilot's replies.
* The system prompt, including `COPILOT_CUSTOM_CONTEXT`, `COPILOT_TONE_OF_RESPONSE` and the user's `aiContext` (see [Per-user context](https://docs.appmixer.com/getting-started/ai-copilot.md#per-user-context)).
* Tool inputs and outputs, such as the flow descriptor, the components available to the user, and inspector field options.
* Example values of output variables from the flow's most recent run, up to `COPILOT_VARIABLES_MAX_EXAMPLE_CHARS` characters each (160 by default). These values are the real data that passed through the flow.

If the data that flows through your flows must not leave the platform, set `COPILOT_VARIABLES_MAX_EXAMPLE_CHARS` to `0`. Copilot then doesn't read run data at all, so it reaches neither the model nor the traces.

Copilot never puts the values of the [LLM gateway headers](https://docs.appmixer.com/getting-started/ai-copilot.md#llm-gateway-headers) (`COPILOT_LLM_HEADERS` and the headers forwarded by `COPILOT_FORWARDED_HEADERS`) into a trace. The Langfuse keys are never logged.

## Relation to OpenTelemetry

Langfuse tracing doesn't depend on the platform's [OpenTelemetry](https://docs.appmixer.com/appmixer-self-managed/monitoring-and-observability.md#opentelemetry) instrumentation, and you can enable either one or both. Copilot sends its traces through its own pipeline, which records every request: a sampling ratio configured for the platform's OpenTelemetry, such as `OTEL_TRACES_SAMPLER`, doesn't drop Copilot traces.

## Verifying the setup

The Appmixer API node logs show whether tracing is active:

* `Copilot Langfuse tracing enabled.` is logged with the base URL when the first chat request after you configure the keys sets up the tracing pipeline.
* `Copilot plugin configuration.` is logged when the plugin loads. It includes `langfuseEnabled` and `langfuseBaseUrl`, but only as they were at startup, so keys added later in the Backoffice don't show in this message.
* `Copilot Langfuse tracing could not be initialized; continuing without it.` means the configuration was rejected. Chat keeps working without traces, and Copilot doesn't try again until the Langfuse configuration changes. The warning is logged once.
* `Copilot Langfuse flush failed.` means traces could not be delivered, usually because the URL is unreachable or the keys are wrong.

If tracing is enabled but no traces appear, check that the keys belong to the project you are looking at, that `COPILOT_LANGFUSE_BASE_URL` matches the region of your Langfuse account, and that the API nodes can reach that URL.

## Other debugging options

* Copilot errors, LLM retries and tool failures are written to the regular Appmixer logs, without the content of the messages.
* On a self-managed installation, you can turn on debug logging for Copilot alone with `LOG_LEVEL_OVERRIDES=system-plugin-copilot:debug` and leave the rest of the node at its usual level. `LOG_LEVEL=debug` also works, but it applies to everything running on the node.
* The **AI usage** page in Insights shows token usage and cost per user and per request. See [Monitoring AI Usage](https://docs.appmixer.com/getting-started/ai-copilot.md#monitoring-ai-usage).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.appmixer.com/getting-started/ai-copilot/langfuse.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
