Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: configure posthog SDK (#8067)

Max Deichmann1dee7092b3f5
diff --git a/packages/shared/src/server/repositories/scores.ts b/packages/shared/src/server/repositories/scores.ts
index 9fd432654f..10b7834a09 100644
--- a/packages/shared/src/server/repositories/scores.ts
+++ b/packages/shared/src/server/repositories/scores.ts
@@ -1335,6 +1335,8 @@ export const getScoresForPostHog = async function* (
s.timestamp as timestamp,
s.name as name,
s.value as value,
+ s.string_value as string_value,
+ s.data_type as data_type,
s.comment as comment,
s.environment as environment,
t.name as trace_name,
@@ -1342,6 +1344,7 @@ export const getScoresForPostHog = async function* (
t.user_id as trace_user_id,
t.release as trace_release,
t.tags as trace_tags,
+ s.metadata as metadata,
t.metadata['$posthog_session_id'] as posthog_session_id
FROM scores s FINAL
LEFT JOIN traces t FINAL ON s.trace_id = t.id AND s.project_id = t.project_id
@@ -1382,6 +1385,9 @@ export const getScoresForPostHog = async function* (
langfuse_score_name: record.name,
langfuse_score_value: record.value,
langfuse_score_comment: record.comment,
+ langfuse_score_metadata: record.metadata,
+ langfuse_score_string_value: record.string_value,
+ langfuse_score_data_type: record.data_type,
langfuse_trace_name: record.trace_name,
langfuse_id: record.id,
langfuse_session_id: record.trace_session_id,
diff --git a/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts b/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts
index a42979090b..43904f98c0 100644
--- a/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts
+++ b/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts
@@ -22,6 +22,10 @@ type PostHogExecutionConfig = {
const POSTHOG_UUID_NAMESPACE = "0f6c91df-d035-4813-b838-9741ba38ef0b";
+const postHogSettings = {
+ flushAt: 1000,
+};
+
const processPostHogTraces = async (config: PostHogExecutionConfig) => {
const postHogTraces = getTracesForPostHog(
config.projectId,
@@ -34,6 +38,16 @@ const processPostHogTraces = async (config: PostHogExecutionConfig) => {
// Send each via PostHog SDK
const posthog = new PostHog(config.decryptedPostHogApiKey, {
host: config.postHogHost,
+ ...postHogSettings,
+ });
+
+ posthog.on("error", (error) => {
+ logger.error(
+ `Error sending traces to PostHog for project ${config.projectId}: ${error}`,
+ );
+ throw new Error(
+ `Error sending traces to PostHog for project ${config.projectId}: ${error}`,
+ );
});
let count = 0;
@@ -74,6 +88,16 @@ const processPostHogGenerations = async (config: PostHogExecutionConfig) => {
// Send each via PostHog SDK
const posthog = new PostHog(config.decryptedPostHogApiKey, {
host: config.postHogHost,
+ ...postHogSettings,
+ });
+
+ posthog.on("error", (error) => {
+ logger.error(
+ `Error sending generations to PostHog for project ${config.projectId}: ${error}`,
+ );
+ throw new Error(
+ `Error sending generations to PostHog for project ${config.projectId}: ${error}`,
+ );
});
let count = 0;
@@ -114,8 +138,17 @@ const processPostHogScores = async (config: PostHogExecutionConfig) => {
// Send each via PostHog SDK
const posthog = new PostHog(config.decryptedPostHogApiKey, {
host: config.postHogHost,
+ ...postHogSettings,
});
+ posthog.on("error", (error) => {
+ logger.error(
+ `Error sending scores to PostHog for project ${config.projectId}: ${error}`,
+ );
+ throw new Error(
+ `Error sending scores to PostHog for project ${config.projectId}: ${error}`,
+ );
+ });
let count = 0;
for await (const score of postHogScores) {
count++;