🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat: add score and score config user tracking events (#2240)
marliessophie2db88101e163
diff --git a/web/src/components/session/index.tsx b/web/src/components/session/index.tsxindex 3d26c6e2e1..eaa63d8e5e 100644--- a/web/src/components/session/index.tsx+++ b/web/src/components/session/index.tsx@@ -207,6 +207,8 @@ const TraceCardList = ({traceId={trace.id}scores={trace.scores}variant="badge"+ type="session"+ source="SessionDetail"/></div></ScrollArea>diff --git a/web/src/components/trace/ObservationPreview.tsx b/web/src/components/trace/ObservationPreview.tsxindex 414801fb9a..3283e50328 100644--- a/web/src/components/trace/ObservationPreview.tsx+++ b/web/src/components/trace/ObservationPreview.tsx@@ -159,6 +159,7 @@ export const ObservationPreview = (props: {traceId={preloadedObservation.traceId}observationId={preloadedObservation.id}scores={props.scores}+ type="observation"/>{observationWithInputAndOutput.data?.type === "GENERATION" && (<JumpToPlaygroundButtondiff --git a/web/src/features/manual-scoring/components/AnnotateButton.tsx b/web/src/features/manual-scoring/components/AnnotateButton.tsxindex 6c7a108683..160e83712f 100644--- a/web/src/features/manual-scoring/components/AnnotateButton.tsx+++ b/web/src/features/manual-scoring/components/AnnotateButton.tsx@@ -1,7 +1,13 @@import { useHasAccess } from "@/src/features/rbac/utils/checkAccess";import React from "react";import { Button } from "@/src/components/ui/button";-import { LockIcon, MessageCircleMore, MessageCircle, X } from "lucide-react";+import {+ LockIcon,+ MessageCircleMore,+ MessageCircle,+ X,+ SquarePen,+} from "lucide-react";import {type ControllerRenderProps,useFieldArray,@@ -56,6 +62,7 @@ import { MultiSelectKeyValues } from "@/src/features/manual-scoring/components/mimport { CommandItem } from "@/src/components/ui/command";import { useRouter } from "next/router";import useLocalStorage from "@/src/components/useLocalStorage";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";const AnnotationScoreDataSchema = z.object({name: z.string(),@@ -84,13 +91,18 @@ export function AnnotateButton({observationId,projectId,variant = "button",+ type = "trace",+ source = "TraceDetail",}: {traceId: string;scores: Score[];observationId?: string;projectId: string;variant?: "button" | "badge";+ type?: "trace" | "observation" | "session";+ source?: "TraceDetail" | "SessionDetail";}) {+ const capture = usePostHogClientCapture();const hasAccess = useHasAccess({projectId,scope: "scores:CUD",@@ -256,7 +268,7 @@ export function AnnotateButton({});if (!!stringValue) {- if (!!score.scoreId)+ if (!!score.scoreId) {await mutUpdateScores.mutateAsync({projectId,...score,@@ -264,7 +276,12 @@ export function AnnotateButton({value: newValue,stringValue,});- else+ capture("score:update", {+ type: type,+ source: source,+ dataType: score.dataType,+ });+ } else {await mutCreateScores.mutateAsync({projectId,traceId,@@ -273,6 +290,12 @@ export function AnnotateButton({value: newValue,stringValue,});+ capture("score:create", {+ type: type,+ source: source,+ dataType: score.dataType,+ });+ }}}};@@ -292,7 +315,7 @@ export function AnnotateButton({}): React.MouseEventHandler<HTMLButtonElement> | undefined {return async () => {const { value, scoreId } = score;- if (!!field.value && !!scoreId && isPresent(value))+ if (!!field.value && !!scoreId && isPresent(value)) {await mutUpdateScores.mutateAsync({projectId,...score,@@ -300,6 +323,11 @@ export function AnnotateButton({id: scoreId,comment,});+ capture(comment ? "score:update_comment" : "score:delete_comment", {+ type: type,+ source: source,+ });+ }};}@@ -336,14 +364,19 @@ export function AnnotateButton({form.clearErrors(`scoreData.${index}.value`);if (isPresent(field.value)) {- if (!!score.scoreId)+ if (!!score.scoreId) {await mutUpdateScores.mutateAsync({projectId,...score,value: Number(field.value),id: score.scoreId,});- else+ capture("score:update", {+ type: type,+ source: source,+ dataType: score.dataType,+ });+ } else {await mutCreateScores.mutateAsync({projectId,traceId,@@ -351,6 +384,12 @@ export function AnnotateButton({observationId,value: Number(field.value),});+ capture("score:create", {+ type: type,+ source: source,+ dataType: score.dataType,+ });+ }}};}@@ -359,12 +398,45 @@ export function AnnotateButton({<Drawer><DrawerTrigger asChild>{variant === "button" ? (- <Button variant="secondary" disabled={!hasAccess}>+ <Button+ variant="secondary"+ disabled={!hasAccess}+ onClick={() =>+ capture(+ Boolean(scores.length)+ ? "score:update_form_open"+ : "score:create_form_open",+ {+ type: type,+ source: source,+ },+ )+ }+ >+ {!hasAccess ? (+ <LockIcon className="mr-2 h-3 w-3" />+ ) : (+ <SquarePen className="mr-2 h-5 w-5" />+ )}<span>Annotate</span>- {!hasAccess ? <LockIcon className="ml-2 h-3 w-3" /> : null}</Button>) : (- <Button className="h-6 rounded-full px-3 text-xs">Annotate</Button>+ <Button+ className="h-6 rounded-full px-3 text-xs"+ onClick={() =>+ capture(+ Boolean(scores.length)+ ? "score:update_form_open"+ : "score:create_form_open",+ {+ type: type,+ source: source,+ },+ )+ }+ >+ Annotate+ </Button>)}</DrawerTrigger><DrawerContent className="h-1/3">@@ -400,9 +472,13 @@ export function AnnotateButton({}))}controlButtons={<CommandItem- onSelect={() =>- router.push(`/project/${projectId}/settings`)- }+ onSelect={() => {+ capture("score_configs:manage_configs_item_click", {+ type: type,+ source: source,+ });+ router.push(`/project/${projectId}/settings`);+ }}>Manage score configs</CommandItem>@@ -683,6 +759,10 @@ export function AnnotateButton({id: score.scoreId,projectId,});+ capture("score:delete", {+ type: type,+ source: source,+ });form.clearErrors(`scoreData.${index}.value`,);diff --git a/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsx b/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsxindex 02e7693eb0..211e072488 100644--- a/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsx+++ b/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsx@@ -37,6 +37,7 @@ import {isNumericDataType,} from "@/src/features/manual-scoring/lib/helpers";import DocPopup from "@/src/components/layouts/doc-popup";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";const availableDataTypes = [ScoreDataType.NUMERIC,@@ -61,6 +62,7 @@ const formSchema = z.object({export function CreateScoreConfigButton({ projectId }: { projectId: string }) {const [open, setOpen] = useState(false);const [formError, setFormError] = useState<string | null>(null);+ const capture = usePostHogClientCapture();const hasAccess = useHasAccess({projectId: projectId,@@ -102,6 +104,9 @@ export function CreateScoreConfigButton({ projectId }: { projectId: string }) {...values,}).then(() => {+ capture("score_configs:create_form_submit", {+ dataType: values.dataType,+ });form.reset();setOpen(false);})diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex 42406c3db2..680c7277fd 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -28,12 +28,15 @@ const events = {],generations: ["export"],score: [+ "create",+ "update","delete","update_form_open","create_form_open",- "update_form_submit",- "create_form_submit",+ "update_comment",+ "delete_comment",],+ score_configs: ["create_form_submit", "manage_configs_item_click"],models: ["delete_button_click", "new_form_submit", "new_form_open"],prompts: ["new_form_submit",