IntegrationsPostHog

PostHog Integration

PostHog is a popular choice for OSS product analytics. While Langfuse offers analytics out of the box, many of our users have asked for a way to integrate their LLM related metrics that they capture with Langfuse into their PostHog dashboards.

We've built an integration to make it easy to answer questions like:

  • "Are my most active users also the ones who are most engaged with my LLM content?"
  • "Does interacting with the LLM feature relate to higher retention rates?"
  • "How does the LLM feature impact my conversion rates?"
  • "Does the user feedback that I capture in Langfuse correlate with the user behavior that I see in PostHog?"

Get started

Enable the integration

Configure this integration in your Langfuse project settings. You will need to provide your PostHog Hostname and API key.

Posthog Integration Settings

Build a dashboard in PostHog

Once integrated, you can build a dashboard in PostHog to visualize your Langfuse metrics (see reference below). Use the AI Metrics template to get started with a pre-built dashboard that includes the most common metrics from Langfuse.

PostHog Dashboard Template

Example PostHog Dashboard

Integration details

On an hourly schedule, Langfuse batches aggregated events and metrics to your PostHog instance.

Metadata matching

Matching of metadata helps to join the data from Langfuse with the data from PostHog:

LangfusePostHogNotes
user_id$distinct_id
observation.start_time, score.timestamptimestampFor legacy events: trace.timestamp and generation.started_at.
trace.metadata.$posthog_session_id$session_idOptional, you need to add the PostHog session id to your Langfuse traces.

User properties

We send the following user properties via '$set':

  • langfuse_user_url: Deeplink to the user profile in Langfuse.

Events

The integration sends one langfuse observation event per observation and one langfuse score event per score.

Is there any additional information that would be helpful? You can request more events or properties here.

Projects using a legacy export source receive different events — see Legacy export sources below.

Event: langfuse observation

One event per observation, covering every observation type.

PropertyDescription
timestampThe start time of the observation.
langfuse_observation_nameThe name of the observation.
langfuse_typeThe observation type: GENERATION, SPAN, EVENT, AGENT, TOOL, CHAIN, RETRIEVER, EVALUATOR, EMBEDDING, or GUARDRAIL.
langfuse_trace_nameName of the trace related to the observation.
langfuse_trace_idThe unique identifier of the trace related to the observation.
langfuse_urlThe URL of the observation on the host platform.
langfuse_user_urlDeeplink to the user profile in Langfuse.
langfuse_idUnique identifier of the observation.
langfuse_cost_usdComputed total cost of the observation.
langfuse_input_unitsNumber of tokens utilized in prompting (for LLM calls).
langfuse_output_unitsNumber of tokens produced (for LLM calls).
langfuse_total_unitsTotal number of tokens consumed (for LLM calls).
langfuse_session_idThe session ID associated with the trace of the observation.
langfuse_project_idThe ID of the project where the observation happened.
langfuse_project_nameThe name of the project where the observation happened.
langfuse_user_idThe user ID that started the trace linked to the observation. In case it's unavailable, it defaults to langfuse_unknown_user.
langfuse_latencyThe observed latency of the observation.
langfuse_time_to_first_tokenThe time taken to generate the first token when streaming.
langfuse_releaseRelease information of the trace attached with the observation.
langfuse_versionThe versioning info about the observation.
langfuse_modelThe model used (for LLM calls).
langfuse_levelThe level associated with the observation.
langfuse_tagsAny tags attached to the trace of the observation.
langfuse_environmentThe environment associated with the observation.
langfuse_event_versionThe integration version with Langfuse.

Event: langfuse score

One event per score.

PropertyDescription
timestampThe time when the score event occurred.
langfuse_score_nameThe name associated with the score.
langfuse_score_valueThe value of the score.
langfuse_score_string_valueThe string value of the score. For BOOLEAN and CATEGORICAL scores, this will be the string representation of the value.
langfuse_score_data_typeThe data type of the score (NUMERIC, BOOLEAN, CATEGORICAL).
langfuse_score_commentAny comments attached with the score.
langfuse_score_metadataAny metadata attached with the score.
langfuse_score_entity_typeThe entity the score is attached to: trace, session, dataset_run, or unknown.
langfuse_dataset_run_idThe unique identifier of the dataset run, for scores attached to a dataset run.
langfuse_trace_nameThe name of the trace associated with the score.
langfuse_trace_idThe unique identifier of the trace associated with the score.
langfuse_user_urlDeeplink to the user profile in Langfuse.
langfuse_idThe unique identification of the score.
langfuse_session_idThe session identification related to the score's trace.
langfuse_project_idThe project identification linked with the score's trace.
langfuse_project_nameThe name of the project linked with the score's trace.
langfuse_user_idThe user ID that triggered the trace tied with the score. If not available, defaults to langfuse_unknown_user.
langfuse_releaseThe release information of the trace associated with the score.
langfuse_tagsAny tags related to the trace of the score.
langfuse_environmentThe environment associated with the score.
langfuse_event_versionThe integration version with Langfuse.

Legacy export sources

Cloud projects created before 2026-05-20 and self-hosted deployments have an Export Source selector in the integration settings (introduced with Langfuse v4, Fast Preview). Cloud projects created on or after 2026-05-20 always use Enriched observations (recommended) — the schema documented above — and can skip this section.

Available options:

  • Enriched observations (recommended): sends the langfuse observation events documented above. Provides significantly better export performance and covers every observation type.
  • Traces and observations (legacy): sends the langfuse trace and langfuse generation events documented below.
  • Traces and observations (legacy) and enriched observations: sends all of the above. This creates duplicate records by design, as a validation aid during migration.

langfuse score events are always sent, regardless of the selected export source.

Traces and observations (legacy) sources may be deprecated in the future. All new export jobs should use Enriched observations (recommended), and existing legacy jobs are strongly recommended to upgrade.

Migrating from the legacy export source

New integrations default to Enriched observations (recommended); existing integrations continue to use Traces and observations (legacy) until changed.

PostHog is a schemaless event store, so no setup is needed on the PostHog side — the new event name and properties appear automatically once you switch. All migration effort goes into the assets built on top of the events: insights, dashboards, funnels, cohorts, alerts, and warehouse syncs.

Keep in mind:

  1. Nothing is backfilled. The sync is watermark-based: the old event streams stop at the switch date and the new one starts. Dashboards keyed on the old event names show a hard cliff — add a PostHog annotation at the cutover date and keep old dashboards around for lookback.
  2. Queries need rewriting, not re-pointing. Insights on langfuse generation become insights on langfuse observation filtered by langfuse_type = 'GENERATION'. Per-trace metrics (total cost, observation count, latency) must be recomputed by aggregating observation events over langfuse_trace_id, since there is no trace-summary event anymore — see changes from legacy to enriched events.
  3. The combined mode double-counts by design. With Traces and observations (legacy) and enriched observations, a generation is exported both as a langfuse generation and as a langfuse observation event. PostHog does not deduplicate across event names, so metrics that sum cost or tokens across both event types double-count during migration. Use this mode only to build and validate new dashboards side by side.
  4. The switch is effectively one-way. Once legacy writes are off, the legacy sources can no longer be selected.

To migrate:

  1. Switch to Traces and observations (legacy) and enriched observations.
  2. Duplicate your dashboards and insights onto the langfuse observation event: filter by langfuse_type, use langfuse_observation_name, and rebuild per-trace metrics as aggregations over langfuse_trace_id.
  3. Validate the new numbers against the old ones side by side. Expect intentional coverage differences: the enriched source includes all observation types, not just generations.
  4. Switch to Enriched observations (recommended) and annotate the cutover date on any legacy dashboards you keep.

For rollout details, see the enriched observations default changelog.

Changes from legacy to enriched events

  • langfuse generation is replaced by langfuse observation. The two events are field-for-field identical, with two exceptions: langfuse_generation_name is renamed to langfuse_observation_name, and a new langfuse_type property carries the observation type.
  • Coverage expands to all observation types. The legacy source only exports generations; the enriched source exports every observation type. Expect a higher event volume after switching — PostHog bills per event. Filter on langfuse_type = GENERATION to reproduce the legacy scope.
  • No standalone trace event. Trace context is available on every observation event via langfuse_trace_id and langfuse_trace_name. The trace-level rollup properties have no enriched equivalent: langfuse_count_observations, the trace-level langfuse_cost_usd and langfuse_latency aggregates, and the trace-scoped langfuse_url. To approximate them, aggregate observation events by langfuse_trace_id.
  • Score events are identical in both sources.
  • Identity and deduplication are unchanged: the distinct id is still derived from langfuse_user_id, $session_id handling is the same, and langfuse_event_version remains 1.0.0 for all events.

Event: langfuse trace

Sent only by the legacy export sources. There is no enriched equivalent — see changes from legacy to enriched events.

PropertyDescription
timestampThe time the event occurred.
langfuse_trace_nameThe name of the trace.
langfuse_urlThe URL of the trace.
langfuse_user_urlDeeplink to the user profile in Langfuse.
langfuse_idThe unique identification of the trace.
langfuse_cost_usdThe total cost associated with the trace.
langfuse_count_observationsThe number of observations in the trace.
langfuse_session_idThe session ID related to the event.
langfuse_project_idAn ID associated with the project related to the event.
langfuse_project_nameThe name of the project related to the event.
langfuse_user_idUser ID related to the event. If it's null, it's marked as langfuse_unknown_user.
langfuse_latencyThe latency of the event.
langfuse_releaseInformation relating to the event release.
langfuse_versionThe version of the event.
langfuse_tagsAny tags associated with the event.
langfuse_environmentThe environment associated with the trace.
langfuse_event_versionThe integration version of Langfuse.

Event: langfuse generation

Sent only by the legacy export sources. Only covers observations of type generation; replaced by langfuse observation in the enriched source.

PropertyDescription
timestampThe start time of the generation.
langfuse_generation_nameThe name of the generation.
langfuse_trace_nameName of the trace related to the generation.
langfuse_trace_idThe unique identifier of the trace related to the generation.
langfuse_urlThe URL of the generation on the host platform.
langfuse_user_urlDeeplink to the user profile in Langfuse.
langfuse_idUnique identifier of the generation.
langfuse_cost_usdComputed total cost of the generation.
langfuse_input_unitsNumber of tokens utilized in prompting the generation.
langfuse_output_unitsNumber of tokens produced by the generation.
langfuse_total_unitsTotal number of tokens consumed in the generation process.
langfuse_session_idThe session ID associated with the trace of the generation.
langfuse_project_idThe project identification where the generation happened.
langfuse_project_nameThe name of the project where the generation happened.
langfuse_user_idThe user ID that started the trace linked to the generation. In case it's unavailable, it defaults to langfuse_unknown_user.
langfuse_latencyThe observed latency of the generation.
langfuse_time_to_first_tokenThe time taken to generate the first token when streaming.
langfuse_releaseRelease information of the trace attached with the generation.
langfuse_versionThe versioning info about the generation.
langfuse_modelThe model used during this generation's process.
langfuse_levelThe level associated with the generation.
langfuse_tagsAny tags attached to the trace of the generation.
langfuse_environmentThe environment associated with the generation.
langfuse_event_versionThe integration version with Langfuse.

Troubleshooting

Missing data in PostHog? Please check that you have correctly entered the PostHog hostname and API key in your Langfuse project settings. Also, if you use the PostHog free-tier, please make sure that you have not exceeded the event limits as PostHog drops events when the limit is reached. Reach out to us if you encounter any other issues with the integration.


Was this page helpful?

Last edited