Skip to content

Commit

Permalink
feat: add trace node
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang committed Mar 20, 2024
1 parent 5ea99ef commit 80195ee
Show file tree
Hide file tree
Showing 7 changed files with 510 additions and 220 deletions.
33 changes: 33 additions & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,22 @@ type Project implements Node {
tokenCountTotal: Int!
latencyMsP50: Float
latencyMsP99: Float
trace(traceId: ID!): Trace
spans(timeRange: TimeRange, traceIds: [ID!], first: Int = 50, last: Int, after: String, before: String, sort: SpanSort, rootSpansOnly: Boolean, filterCondition: String): SpanConnection!

"""
Names of all available evaluations for traces. (The list contains no duplicates.)
"""
traceEvaluationNames: [String!]!

"""
Names of all available evaluations for spans. (The list contains no duplicates.)
"""
spanEvaluationNames: [String!]!

"""Names of available document evaluations."""
documentEvaluationNames(spanId: ID): [String!]!
traceEvaluationSummary(evaluationName: String!, timeRange: TimeRange): EvaluationSummary
spanEvaluationSummary(evaluationName: String!, timeRange: TimeRange, filterCondition: String): EvaluationSummary
documentEvaluationSummary(evaluationName: String!, timeRange: TimeRange, filterCondition: String): DocumentEvaluationSummary
streamingLastUpdatedAt: DateTime
Expand Down Expand Up @@ -795,6 +802,32 @@ type TimeSeriesDataPoint {
value: Float
}

type Trace {
traceId: ID!
spans(first: Int, last: Int, after: String, before: String): SpanConnection!

"""Evaluations associated with the trace"""
traceEvaluations: [TraceEvaluation!]!
}

type TraceEvaluation implements Evaluation {
"""Name of the evaluation, e.g. 'helpfulness' or 'relevance'."""
name: String!

"""Result of the evaluation in the form of a numeric score."""
score: Float

"""
Result of the evaluation in the form of a string, e.g. 'helpful' or 'not helpful'. Note that the label is not necessarily binary.
"""
label: String

"""
The evaluator's explanation for the evaluation result (i.e. score or label, or both) given to the subject.
"""
explanation: String
}

type UMAPPoint {
id: GlobalID!

Expand Down
111 changes: 54 additions & 57 deletions app/src/pages/trace/TracePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ import {
import { SpanEvaluationsTable } from "./SpanEvaluationsTable";

type Span = NonNullable<
TracePageQuery$data["project"]["spans"]
>["edges"][number]["span"];
TracePageQuery$data["project"]["trace"]
>["spans"]["edges"][number]["span"];
type DocumentEvaluation = Span["documentEvaluations"][number];
/**
* A span attribute object that is a map of string to an unknown value
Expand Down Expand Up @@ -181,59 +181,57 @@ export function TracePage() {
query TracePageQuery($traceId: ID!, $id: GlobalID!) {
project: node(id: $id) {
... on Project {
spans(
traceIds: [$traceId]
sort: { col: startTime, dir: asc }
first: 1000
) {
edges {
span: node {
context {
spanId
}
name
spanKind
statusCode: propagatedStatusCode
statusMessage
startTime
parentId
latencyMs
tokenCountTotal
tokenCountPrompt
tokenCountCompletion
input {
value
mimeType
}
output {
value
mimeType
}
attributes
events {
name
message
timestamp
}
spanEvaluations {
name
label
score
}
documentRetrievalMetrics {
evaluationName
ndcg
precision
hit
}
documentEvaluations {
documentPosition
trace(traceId: $traceId) {
spans {
edges {
span: node {
context {
spanId
}
name
label
score
explanation
spanKind
statusCode: propagatedStatusCode
statusMessage
startTime
parentId
latencyMs
tokenCountTotal
tokenCountPrompt
tokenCountCompletion
input {
value
mimeType
}
output {
value
mimeType
}
attributes
events {
name
message
timestamp
}
spanEvaluations {
name
label
score
}
documentRetrievalMetrics {
evaluationName
ndcg
precision
hit
}
documentEvaluations {
documentPosition
name
label
score
explanation
}
...SpanEvaluationsTable_evals
}
...SpanEvaluationsTable_evals
}
}
}
Expand All @@ -246,10 +244,9 @@ export function TracePage() {
fetchPolicy: "store-and-network",
}
);
const spansList = useMemo(() => {
const gqlSpans =
data.project.spans || ([] as NonNullable<typeof data.project.spans>);
return gqlSpans.edges.map((edge) => edge.span);
const spansList: Span[] = useMemo(() => {
const gqlSpans = data.project.trace?.spans.edges || [];
return gqlSpans.map((node) => node.span);
}, [data]);
const urlSelectedSpanId = searchParams.get("selectedSpanId");
const selectedSpanId = urlSelectedSpanId ?? spansList[0].context.spanId;
Expand Down
Loading

0 comments on commit 80195ee

Please sign in to comment.