Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
fetchAllPreviewTraces,
fetchPreviewTrace,
isSpansResponse,
isTracesResponse,
transformTracesResponseToTree,
Expand All @@ -16,7 +18,6 @@ import {AnnotationDto} from "@/oss/lib/hooks/useAnnotations/types"
import {getNodeById, observabilityTransformer} from "@/oss/lib/traces/observability_helpers"
import {queryAllAnnotations} from "@/oss/services/annotations/api"
import {AgentaTreeDTO, TracesWithAnnotations} from "@/oss/services/observability/types"
import {fetchAllPreviewTraces, fetchPreviewTrace} from "@/oss/services/tracing/api"
import {SpanLink, TraceSpanNode, TracesResponse} from "@/oss/services/tracing/types"
import {selectedAppIdAtom} from "@/oss/state/app/selectors/app"
import {getOrgValues} from "@/oss/state/org"
Expand Down Expand Up @@ -122,7 +123,7 @@ export const sessionTracesQueryAtom = atomWithQuery((get) => {
queryKey: ["session-traces", projectId, appId, sessionId],
queryFn: async () => {
if (!sessionId) return {traces: [], count: 0}
return fetchAllPreviewTraces(params, appId as string)
return fetchAllPreviewTraces(params, appId as string, projectId ?? "")
},
enabled: sessionExists && Boolean(appId || projectId) && Boolean(sessionId),
refetchOnWindowFocus: false,
Expand Down Expand Up @@ -391,9 +392,10 @@ export const sessionDrawerAnnotationLinkTracesQueryAtom = atomWithQuery<
Record<string, TracesWithAnnotations[]>
>((get) => {
const targets = get(sessionDrawerAnnotationLinkTargetsAtom)
const projectId = get(projectIdAtom)

return {
queryKey: ["session-drawer-annotation-links", targets],
queryKey: ["session-drawer-annotation-links", targets, projectId ?? "none"],
enabled: Array.isArray(targets) && targets.length > 0,
refetchOnWindowFocus: false,
queryFn: async () => {
Expand All @@ -402,7 +404,9 @@ export const sessionDrawerAnnotationLinkTracesQueryAtom = atomWithQuery<

const traceResponses = await Promise.all(
uniqueTraceIds.map(async (traceId) => {
const response = await fetchPreviewTrace(traceId)
// `any`: see traceDrawerStore — loose to match the runtime
// multi-shape handling until AGE-3788 Phase 7 unifies FE types.
const response: any = await fetchPreviewTrace(traceId, projectId ?? "")
const tree = response?.response?.tree as AgentaTreeDTO | undefined

if (tree) {
Expand All @@ -418,7 +422,7 @@ export const sessionDrawerAnnotationLinkTracesQueryAtom = atomWithQuery<
return {
traceId,
nodes: transformTracingResponse(
transformTracesResponseToTree(fallback),
transformTracesResponseToTree(fallback as never),
) as unknown as TracesWithAnnotations[],
}
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {useState} from "react"

import {deletePreviewTrace} from "@agenta/entities/trace"
import {DeleteOutlined} from "@ant-design/icons"
import {Modal} from "antd"
import {useAtom, useAtomValue, useSetAtom} from "jotai"
import Router from "next/router"

import {deletePreviewTrace} from "@/oss/services/tracing/api"
import {useObservability} from "@/oss/state/newObservability"
import {getProjectValues} from "@/oss/state/project"
import {traceIdAtom} from "@/oss/state/url/trace"

import {closeTraceDrawerAtom} from "../../store/traceDrawerStore"
Expand All @@ -27,7 +28,8 @@ const DeleteTraceModal = () => {
const handleDelete = async () => {
try {
setIsLoading(true)
await Promise.all(traceIds.map((id) => deletePreviewTrace(id)))
const {projectId} = getProjectValues()
await Promise.all(traceIds.map((id) => deletePreviewTrace(id, projectId ?? "")))
await fetchTraces()

const isCurrentTraceDeleted = traceIds.includes(currentTraceId || "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useCallback, useEffect, useMemo, useState} from "react"

import {
fetchAllPreviewTraces,
isSpansResponse,
isTracesResponse,
transformTracesResponseToTree,
Expand All @@ -17,11 +18,11 @@ import {
traceDrawerBackTargetAtom,
traceDrawerIsLinkedViewAtom,
} from "@/oss/components/SharedDrawers/TraceDrawer/store/traceDrawerStore"
import {fetchAllPreviewTraces} from "@/oss/services/tracing/api"
import {TraceSpanNode} from "@/oss/services/tracing/types"
import {selectedAppIdAtom} from "@/oss/state/app/selectors/app"
import {useObservability} from "@/oss/state/newObservability"
import buildTraceQueryParams from "@/oss/state/newObservability/utils/buildTraceQueryParams"
import {getProjectValues} from "@/oss/state/project"

import {getNodeTimestamp, getSpanIdFromNode, getTraceIdFromNode, toISOString} from "./assets/helper"
import {NavSource, NavState, TraceHeaderProps} from "./assets/types"
Expand Down Expand Up @@ -177,7 +178,8 @@ const TraceHeader = ({
}

try {
const response = await fetchAllPreviewTraces(params, appId)
const {projectId} = getProjectValues()
const response = await fetchAllPreviewTraces(params, appId, projectId ?? "")

console.debug("[TraceNav] fetchRelative:response", {
direction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {transformTracesResponseToTree, transformTracingResponse} from "@agenta/entities/trace"
import {
fetchPreviewTrace,
transformTracesResponseToTree,
transformTracingResponse,
} from "@agenta/entities/trace"
import {atom} from "jotai"
import {atomWithStorage} from "jotai/utils"
import {atomWithImmer} from "jotai-immer"
Expand All @@ -10,9 +14,9 @@ import {AnnotationDto} from "@/oss/lib/hooks/useAnnotations/types"
import {getNodeById, observabilityTransformer} from "@/oss/lib/traces/observability_helpers"
import {queryAllAnnotations} from "@/oss/services/annotations/api"
import {AgentaTreeDTO, TracesWithAnnotations} from "@/oss/services/observability/types"
import {fetchPreviewTrace} from "@/oss/services/tracing/api"
import {SpanLink, TracesResponse} from "@/oss/services/tracing/types"
import {getOrgValues} from "@/oss/state/org"
import {projectIdAtom} from "@/oss/state/project"

export type TraceDrawerSpanLink = SpanLink & {key?: string}
interface AnnotationLinkTarget {
Expand Down Expand Up @@ -130,14 +134,15 @@ export const setTraceDrawerTraceAtom = atom(
// Fetches the currently selected trace.
export const traceDrawerQueryAtom = atomWithQuery((get) => {
const traceId = get(traceDrawerTraceIdAtom)
const projectId = get(projectIdAtom)

return {
queryKey: ["trace-drawer", traceId ?? "none"],
queryKey: ["trace-drawer", traceId ?? "none", projectId ?? "none"],
enabled: Boolean(traceId),
refetchOnWindowFocus: false,
queryFn: async () => {
if (!traceId) return null
return fetchPreviewTrace(traceId)
return fetchPreviewTrace(traceId, projectId ?? "")
},
}
})
Expand Down Expand Up @@ -171,7 +176,11 @@ const flattenTraces = (nodes: TracesWithAnnotations[]): TracesWithAnnotations[]
}

export const traceDrawerBaseTracesAtom = atom<TracesWithAnnotations[]>((get) => {
const {data: traceResponse} = get(traceDrawerQueryAtom)
// `any` on purpose: these stores accept multiple response shapes (legacy map,
// agenta `.response.tree`, new typed TracesResponse) and branch at runtime via
// normalizeTracesResponse. AGE-3788 Phase 7 unifies the FE trace types; until
// then the loose local mirrors the pre-migration (untyped) handling.
const traceResponse: any = get(traceDrawerQueryAtom).data
const tree = traceResponse?.response?.tree as AgentaTreeDTO | undefined

if (tree) {
Expand All @@ -182,7 +191,7 @@ export const traceDrawerBaseTracesAtom = atom<TracesWithAnnotations[]>((get) =>
if (!fallback) return []

return transformTracingResponse(
transformTracesResponseToTree(fallback),
transformTracesResponseToTree(fallback as never),
) as unknown as TracesWithAnnotations[]
})

Expand Down Expand Up @@ -287,9 +296,10 @@ export const annotationLinkTargetsAtom = atom<AnnotationLinkTarget[]>((get) => {
export const annotationLinkTracesQueryAtom = atomWithQuery<Record<string, TracesWithAnnotations[]>>(
(get) => {
const targets = get(annotationLinkTargetsAtom)
const projectId = get(projectIdAtom)

return {
queryKey: ["trace-drawer-annotation-links", targets],
queryKey: ["trace-drawer-annotation-links", targets, projectId ?? "none"],
enabled: Array.isArray(targets) && targets.length > 0,
refetchOnWindowFocus: false,
queryFn: async () => {
Expand All @@ -298,7 +308,7 @@ export const annotationLinkTracesQueryAtom = atomWithQuery<Record<string, Traces

const traceResponses = await Promise.all(
uniqueTraceIds.map(async (traceId) => {
const response = await fetchPreviewTrace(traceId)
const response: any = await fetchPreviewTrace(traceId, projectId ?? "")
const tree = response?.response?.tree as AgentaTreeDTO | undefined

if (tree) {
Expand All @@ -314,7 +324,7 @@ export const annotationLinkTracesQueryAtom = atomWithQuery<Record<string, Traces
return {
traceId,
nodes: transformTracingResponse(
transformTracesResponseToTree(fallback),
transformTracesResponseToTree(fallback as never),
) as unknown as TracesWithAnnotations[],
}
}),
Expand Down Expand Up @@ -377,9 +387,10 @@ export const linkedSpanTargetsAtom = atom<AnnotationLinkTarget[]>((get) => {
export const linkedSpanTracesQueryAtom = atomWithQuery<Record<string, TracesWithAnnotations[]>>(
(get) => {
const targets = get(linkedSpanTargetsAtom)
const projectId = get(projectIdAtom)

return {
queryKey: ["trace-drawer-linked-spans", targets],
queryKey: ["trace-drawer-linked-spans", targets, projectId ?? "none"],
enabled: Array.isArray(targets) && targets.length > 0,
refetchOnWindowFocus: false,
queryFn: async () => {
Expand All @@ -396,7 +407,7 @@ export const linkedSpanTracesQueryAtom = atomWithQuery<Record<string, TracesWith

const traceResponses = await Promise.all(
missingTraceIds.map(async (traceId) => {
const response = await fetchPreviewTrace(traceId)
const response: any = await fetchPreviewTrace(traceId, projectId ?? "")
const tree = response?.response?.tree as AgentaTreeDTO | undefined

if (tree) {
Expand All @@ -412,7 +423,7 @@ export const linkedSpanTracesQueryAtom = atomWithQuery<Record<string, TracesWith
return {
traceId,
nodes: transformTracingResponse(
transformTracesResponseToTree(fallback),
transformTracesResponseToTree(fallback as never),
) as unknown as TracesWithAnnotations[],
}
}),
Expand Down
12 changes: 8 additions & 4 deletions web/oss/src/lib/types_ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ export interface GenerationDashboardData {
cost: number
latency: number
total_tokens: number
prompt_tokens: number
completion_tokens: number
enviornment: string
variant: string
// AGE-3788: optional — the new /spans/analytics/query metrics carry no
// prompt/completion token split or per-bucket environment/variant, and
// the legacy transform never populated them. Kept in sync with the
// duplicate interface in services/tracing/types.
prompt_tokens?: number
completion_tokens?: number
enviornment?: string
variant?: string
}[]
total_count: number
failure_rate: number
Expand Down
Loading
Loading