> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Import Langfuse Cloud trace data

> How to load LLM trace data exported from Langfuse Cloud into ClickHouse Cloud using ClickPipes.

This guide walks you through loading LLM trace data from [Langfuse Cloud](https://cloud.langfuse.com/) into ClickHouse Cloud for real-time analytics.

<h2 id="export-from-langfuse-cloud">
  Export from Langfuse Cloud
</h2>

Follow [this guide](https://langfuse.com/docs/api-and-data-platform/features/export-to-blob-storage) to configure a Blob Storage integration in Langfuse Cloud for scheduled exports. You can schedule exports of your trace data to object storage as often as every `20 minutes` or on an `hourly`, `daily`, or `weekly` schedule. By default, each export contains your `observations` (enriched with trace attributes) and `scores`.

<h3 id="exported-file-layout">
  Exported file layout
</h3>

The Blob Storage integration in Langfuse Cloud writes data to the target bucket or storage container using the following directory structure:

```text theme={null}
{prefix}{project-id}/
├── observations_v2/   # observations enriched with trace attributes
├── scores/            # scores
└── manifests/         # one JSON file per completed run with export metadata
```

<h2 id="import-into-clickhouse-cloud">
  Import into ClickHouse Cloud
</h2>

Once a Blob Storage integration is configured in Langfuse Cloud, trace data will be exported to the target bucket or storage container on a schedule. To import that data into ClickHouse Cloud, you can use [ClickPipes](/integrations/clickpipes) and its managed object storage connectors:

| Data source                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Details                                                                                                  |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| <span style={{display: 'inline-flex', alignItems: 'flex-start'}}><img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/oiVn1yLOSIt50Ty-/images/integrations/logos/amazon_s3_logo.svg?fit=max&auto=format&n=oiVn1yLOSIt50Ty-&q=85&s=b9c1ed38130460286e88176a013fb947" alt="Amazon S3 logo" className="integration-table-logo" width="24" height="24" data-path="images/integrations/logos/amazon_s3_logo.svg" /><span><strong>Amazon S3</strong><br /><em>and S3-compatible object stores</em></span></span> | Integrate using [S3 ClickPipes](/integrations/clickpipes/object-storage/amazon-s3/overview).             |
| <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/oiVn1yLOSIt50Ty-/images/integrations/logos/gcs.svg?fit=max&auto=format&n=oiVn1yLOSIt50Ty-&q=85&s=ac4a49fea3ca0ee58a11ccb66fce8c33" alt="Google Cloud Storage logo" className="integration-table-logo" width="24" height="24" data-path="images/integrations/logos/gcs.svg" /> **Google Cloud Storage**                                                                                                                                                                                                                  | Integrate using [GCS ClickPipes](/integrations/clickpipes/object-storage/google-cloud-storage/overview). |
| <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/oiVn1yLOSIt50Ty-/images/integrations/logos/azureblobstorage.svg?fit=max&auto=format&n=oiVn1yLOSIt50Ty-&q=85&s=e88a2715f451e11d78d11f7bad3d96b2" alt="Azure Blob Storage logo" className="integration-table-logo" width="24" height="24" data-path="images/integrations/logos/azureblobstorage.svg" /> **Azure Blob Storage**                                                                                                                | Integrate using [ABS ClickPipes](/integrations/clickpipes/object-storage/azure-blob-storage/overview).   |

<h3 id="create-a-clickpipe">
  Create a ClickPipe
</h3>

This example uses the S3 ClickPipe to import data from an S3 bucket receiving scheduled exports from Langfuse Cloud, and can be used as a blueprint for all object storage export targets. For data source-specific guidance, see the [ClickPipes documentation](/integrations/clickpipes).

<Steps>
  <Step title="Select the data source" id="1-select-the-data-source">
    **1.** In ClickHouse Cloud, select **Data sources** in the main navigation menu and click **Create ClickPipe**.

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/cp_step0.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=5c127cc5de6fe7160371dce223f06b60" alt="Create ClickPipe" width="2606" height="790" data-path="images/integrations/data-ingestion/clickpipes/cp_step0.webp" />
    </Frame>

    **2.** Click the **Amazon S3** tile. You can also use this tile to connect to other S3-compatible services not listed in the ClickPipes UI.

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/object-storage/amazon-s3/cp_step1.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=486454546bfb918f198b6ff6bb18dddf" alt="Select the Amazon S3 data source" width="3016" height="954" data-path="images/integrations/data-ingestion/clickpipes/object-storage/amazon-s3/cp_step1.webp" />
    </Frame>
  </Step>

  <Step title="Set up the connection" id="2-set-up-the-connection">
    **1.** Fill in the details ClickPipes needs to connect to and authenticate with the bucket receiving your Langfuse Cloud exports.

    * **Authentication method**: the S3 ClickPipe supports [IAM credentials](/integrations/clickpipes/object-storage/amazon-s3/overview#iam-credentials) (`Credentials`) and [IAM role-based authentication](/integrations/clickpipes/object-storage/amazon-s3/overview#iam-role) (`IAM role`). ClickPipes only needs read access to the bucket. See the [reference documentation](/integrations/clickpipes/object-storage/amazon-s3/overview#access-control) for guidance on authentication and permissions.

    * **S3 file path**: point the ClickPipe at a sub-directory and use a `*` wildcard to match every exported file. You **must** create one ClickPipe per sub-directory, given that the exported files under each sub-directory have different schemas.

      | Sub-directory      | File path                                                                                     |
      | ------------------ | --------------------------------------------------------------------------------------------- |
      | `observations_v2/` | `https://{bucket-name}.s3.{region-code}.amazonaws.com/{prefix}{project-id}/observations_v2/*` |
      | `scores/`          | `https://{bucket-name}.s3.{region-code}.amazonaws.com/{prefix}{project-id}/scores/*`          |

      See the [reference documentation](/integrations/clickpipes/object-storage/amazon-s3/overview#file-pattern-matching) for guidance on supported patterns, including how to match files across nested prefixes.

    **2.** Select **Continuous ingestion** so that new files are automatically ingested as Langfuse writes them to the target bucket.

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/ia9MOEZ7z1U3Lp1c/images/use-cases/AI_ML/Langfuse/cp_continuous_ingestion.webp?fit=max&auto=format&n=ia9MOEZ7z1U3Lp1c&q=85&s=cdb46ac36ff430b00cad2fb74cf790dc" alt="Connection details for a Langfuse export, with continuous ingestion enabled." width="3008" height="1542" data-path="images/use-cases/AI_ML/Langfuse/cp_continuous_ingestion.webp" />
    </Frame>

    **3.** Click **Incoming data**. ClickPipes will fetch metadata from your bucket and infer the schema for the target table in the next step.
  </Step>

  <Step title="Validate incoming data" id="3-validate-incoming-data">
    **1.** ClickPipes will connect to your bucket and list the files in the specified path, inferring the file format. In this example, we used the default export file format in Langfuse Cloud (Parquet).

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/ia9MOEZ7z1U3Lp1c/images/use-cases/AI_ML/Langfuse/cp_incoming_data.webp?fit=max&auto=format&n=ia9MOEZ7z1U3Lp1c&q=85&s=c643da67f4674b87acee17b467f89f4c" alt="Files matching the Langfuse export path, with the file type set to Parquet" width="3014" height="1574" data-path="images/use-cases/AI_ML/Langfuse/cp_incoming_data.webp" />
    </Frame>

    **2.** Click **Parse information**. ClickPipes will use a sample file to infer the schema of the exported data and automatically map the source fields to a ClickHouse target table.
  </Step>

  <Step title="Configure the target" id="4-configure-target">
    **1.** In this step, you can review the inferred schema and customize the configuration of the target table, including adjusting the data type mapping, defining the [sorting key](/best-practices/choosing-a-primary-key), and choosing the [table engine](/reference/engines/table-engines).

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/ia9MOEZ7z1U3Lp1c/images/use-cases/AI_ML/Langfuse/cp_table_settings.webp?fit=max&auto=format&n=ia9MOEZ7z1U3Lp1c&q=85&s=ced9ea670e911bb493768d3a046ad599" alt="A scores export writing to a dedicated langfuse database, with the sorting key set to environment, name, timestamp, trace_id, observation_id and id" width="3014" height="1578" data-path="images/use-cases/AI_ML/Langfuse/cp_table_settings.webp" />
    </Frame>

    Under **Upload data to**, keep **New table** selected and set:

    * **Database** and **Name**: a dedicated database for your Langfuse data (e.g., `langfuse`) and a human-readable name for the destination table (e.g., `scores`). ClickPipes defaults to the `default.s3-<uuid>` to avoid naming collisions.

    * **Sorting key**: the [ordering key](/best-practices/choosing-a-primary-key) of the destination table, which determines how ClickHouse persists the data on disk. For optimal performance, the sorting key should match your data access patterns so that queries can skip reading as much data as possible.

      | Sub-directory      | Destination table | Suggested sorting key                                        |
      | ------------------ | ----------------- | ------------------------------------------------------------ |
      | `observations_v2/` | `observations_v2` | `environment, start_time, trace_id, id`                      |
      | `scores/`          | `scores`          | `environment, name, timestamp, trace_id, observation_id, id` |

      This key is also used for de-duplication in `ReplacingMergeTree` tables, so the set of columns must also uniquely identify a record. If you load **multiple Langfuse projects** into one table, prepend `project_id` to the sorting key. See the [reference documentation](/best-practices/choosing-a-primary-key) for guidance on choosing a sorting key.

    * **Partition by**: leave blank unless you plan to expire old traces. [Partitioning](/best-practices/choosing-a-partitioning-key) in ClickHouse is used for data management, rather than query optimization; the suggested sorting key already prunes time-range queries. If you do need retention, partition by the time column (`toYYYYMM(start_time)`, or `toYYYYMM(timestamp)` for `scores`) so that expiring a month of traces is a single `DROP PARTITION` operation.

    **2.** Next, expand **Advanced settings** and set the **Engine** to [`ReplacingMergeTree`](/engines/table-engines/mergetree-family/replacingmergetree) to ensure deduplication, using `updated_at` as the **Version** column.

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/ia9MOEZ7z1U3Lp1c/images/use-cases/AI_ML/Langfuse/cp_advanced_settings.webp?fit=max&auto=format&n=ia9MOEZ7z1U3Lp1c&q=85&s=47787fe4b88fedb7b72a63a6aa51fb31" alt="Advanced settings with the ReplacingMergeTree engine and updated_at as the version column" width="2400" height="484" data-path="images/use-cases/AI_ML/Langfuse/cp_advanced_settings.webp" />
    </Frame>

    Export windows in the Langfuse Cloud Blob Storage integration are inclusive on both bounds, so the same record can land in more than one exported file. Unless your analytical query patterns are idempotent (e.g., `uniq()`, `max()`, `min()`), you **must** handle deduplication as part of the downstream data model using `ReplacingMergeTree` as the target engine.

    <Note>
      **Deduplicate with ReplacingMergeTree**

      This table engine collapses duplicates using background merges. For full de-duplication on read (i.e., merge-on-read semantics), you **must** use the `FINAL` modifier (or `argMax()`-style aggregations) at query time.
    </Note>
  </Step>

  <Step title="Configure permissions" id="5-configure-permissions">
    ClickPipes creates a dedicated user for writing data into the destination table. Select a role for this internal user using a custom role or one of the predefined roles:

    * `Full access`: with full access to the cluster. Required if you use a materialized view or dictionary with the destination table.
    * `Only destination table`: with `INSERT` permissions to the destination table only.

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/Qdrmbc1T54ihl0_n/images/integrations/data-ingestion/clickpipes/cp_step5.webp?fit=max&auto=format&n=Qdrmbc1T54ihl0_n&q=85&s=3a3657fe0c594a1217d71290f27d096a" alt="Permissions" width="2736" height="1318" data-path="images/integrations/data-ingestion/clickpipes/cp_step5.webp" />
    </Frame>

    Click **Complete setup** to create the ClickPipe.
  </Step>

  <Step title="Complete setup" id="6-complete-setup">
    And you're all set! ClickPipes will first perform an historical backfill of all files in the specified path and then start ingesting new files as they land in the bucket.

    <Frame>
      <img src="https://mintcdn.com/private-7c7dfe99-detect-table-modification/ia9MOEZ7z1U3Lp1c/images/use-cases/AI_ML/Langfuse/cp_clickpipes_running.webp?fit=max&auto=format&n=ia9MOEZ7z1U3Lp1c&q=85&s=b68b198a3be0ed1249eaf46a8bbe3fac" alt="The observations and scores ClickPipes running under Data sources" width="3020" height="874" data-path="images/use-cases/AI_ML/Langfuse/cp_clickpipes_running.webp" />
    </Frame>

    Repeat the steps in this guide for each sub-directory you want to import into ClickHouse Cloud.
  </Step>
</Steps>

<h3 id="query-trace-data">
  Query trace data
</h3>

Once the ClickPipes are up and running, you can query your Langfuse Cloud trace data directly in ClickHouse Cloud. The examples below cover some common query patterns: cost and latency rollups, reconstructing a single trace, and correlating scores with models and prompts.

<h4 id="time-bucketed-metric-rollups">
  Time-bucketed metric rollups
</h4>

<Tip>
  Some fields, like `usage_details` and `cost_details`, are exported as `Map` columns. Use a key lookup to read a single value (e.g., `sum(cost_details['total'])`).
</Tip>

```sql theme={null}
SELECT
    toStartOfHour(start_time) AS t,
    provided_model_name,
    count()                        AS spans,
    quantile(0.95)(latency)        AS p95_latency,
    sum(total_cost)                AS cost,
    sum(usage_details['total'])    AS tokens
FROM observations_v2 FINAL
WHERE start_time >= now() - INTERVAL 7 DAY
-- AND environment = '<environment>'
GROUP BY t, provided_model_name
ORDER BY t;
```

<h4 id="trace-reconstruction">
  Trace reconstruction
</h4>

```sql theme={null}
SELECT *
FROM observations_v2 FINAL
WHERE trace_id = '<trace_id>'
ORDER BY start_time;
```

<h4 id="quality-analysis">
  Quality analysis
</h4>

```sql theme={null}
SELECT
    o.provided_model_name,
    s.name,
    avg(s.value) AS avg_score
FROM "s3-26237f63-84dc-4a7d-a0e1-7361cf55ee0b" AS s FINAL
JOIN "s3-80899034-ce1e-4dc9-a4e6-b059ddec4175" AS o FINAL ON s.trace_id = o.trace_id
--WHERE s.environment = '<environment>'
GROUP BY o.provided_model_name, s.name
ORDER BY avg_score DESC;
```

<h2 id="see-also">
  See also
</h2>

* [Langfuse and ClickHouse](/products/cloud/features/ai-ml/langfuse)
* [Langfuse Cloud Blob Storage export](https://langfuse.com/docs/api-and-data-platform/features/export-to-blob-storage)
* [ClickPipes for object storage](/integrations/clickpipes/object-storage/amazon-s3/overview)
