LLM Observability and Tracing using LangFuse Ingestion - n8n Workflow

Use this advanced n8n workflow to capture execution metrics, token usage, and performance data from your AI applications and send them automatically to LangFuse for deep observability. A powerful addition to your n8n templates collection.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

AI/ML Engineers: Who need reliable tracing of their LLM operations. n8n Automation Specialists: Looking for robust observability solutions for complex n8n workflow automations. Developers: Integrating LangFuse with their self-hosted or cloud n8n setups. Performance Analysts: Requiring detailed token usage and latency data per AI model run.

Overview

Maintaining visibility into AI application performance is crucial. This specialized n8n workflow solves the challenge of scattered execution data by consolidating detailed performance metrics—including prompt/completion tokens, latency, and model usage—and pushing them to LangFuse, a dedicated LLM observability platform. This sophisticated n8n template ensures that every single AI execution within your primary n8n workflow is tracked and analyzed. Utilizing the native n8n node for API interaction, combined with powerful JavaScript scripting, this automation provides essential insights that are difficult to gather otherwise, turning opaque AI steps into actionable data points. It is a vital component for anyone running production-grade AI applications using n8n.

How it Works

This n8n workflow is designed to be triggered asynchronously by another parent n8n workflow after an AI task completes.


  1. Trigger: The process begins with the When Executed by Another Workflow n8n trigger, receiving the executionid of the completed AI run.

  2. Deduplication & Delay: The Remove Duplicates n8n node ensures idempotent processing. A subsequent Wait n8n node introduces a crucial 80-second delay, allowing the source execution data (especially token totals and run metrics) to finalize within the n8n system before retrieval.

  3. Data Fetching: The dedicated n8n node connects via the n8n API to fetch the complete execution data associated with the received executionid.

  4. Data Structuring: The first Code: structure execution data n8n node executes complex logic. It processes the raw execution results, identifies all individual LLM calls (e.g., 'OpenAI Chat Model' runs), calculates latency and token usage per run, and links them back to source 'Get a prompt' nodes, outputting a structured array of perModelRuns.

  5. Iteration: The Split Out and Loop Over Items n8n nodes break down the consolidated list of AI runs into individual items, allowing separate LangFuse tracking for each LLM execution step within the overall n8n workflow.

  6. LangFuse Payload Preparation: The second Code: prepare JSON for LF n8n node constructs the necessary LangFuse ingestion payload for each run, creating trace-create (for workflow context) and generation-create (for the specific LLM output) events.

  7. Submission: Finally, the HTTP Request n8n node securely submits the prepared batch data to the LangFuse Ingestion API endpoint, completing the observability cycle for this n8n execution.

Installation Guide

To implement this powerful n8n workflow template, follow these steps:


  1. Import: Copy the provided n8n workflow JSON code and paste it into your n8n instance using the 'New' -> 'Import from JSON' function.

  2. n8n API Credentials: You must set up a dedicated credential for the internal n8n node. This requires creating an 'n8n API' credential in your instance, enabling the workflow to read execution data.

  3. LangFuse Credentials: Configure the HTTP Request n8n node with LangFuse API credentials. Edit the HTTP Request node and navigate to the Authentication section. Select Generic Credential Type and choose HTTP Basic Auth.* Create a new credential where the Username is your LangFuse Public Key and the Password is your LangFuse Secret Key.

  4. Execution Trigger: Ensure your primary AI n8n workflow is configured to call this tracing n8n workflow using the 'Execute Workflow' n8n node, passing the $execution.id of the parent run as the execution_id parameter.

Node Details

When Executed by Another Workflow (n8n trigger): Starts the workflow when called by another n8n process, receiving the execution_id of the run to be monitored.
n8n (n8n node): Fetches comprehensive data about the target execution using the internal n8n API. Key configuration: Resource: execution, Operation: get, dynamically uses the received executionId.
Wait to get an execution data (n8n node): Implements an 80-second pause. This wait is critical to ensure that all internal metrics, especially token usage and final step outputs, are available in the execution history before retrieval.
Code: structure execution data (n8n node): The analytical heart of this n8n template. This custom code node parses the nested execution data, identifies and extracts LLM inputs (promptText), outputs (completionText), token counts, and latency (latencyMs) for every individual model run. It aggregates this data into a usable perModelRuns array.
Split Out / Loop Over Items (n8n nodes): Used together to iterate through the array of structured AI runs (perModelRuns) generated by the previous Code node, ensuring each run is handled as a separate LangFuse generation event.
Code: prepare JSON for LF (n8n node): Transforms the structured run data into the specific JSON payload required by the LangFuse Ingestion API, generating trace-create and generation-create event objects.


  • HTTP Request (n8n node): Sends the final observability payload to the LangFuse API endpoint, using Basic Authentication configured with the LangFuse Public and Secret keys.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Artem Makarov
Artem Makarov

Featured*