Skip to content

Commit 155fc5e

Browse files
committed
cleaned up what is returned from EventRepository.getSpan
1 parent 2c0b7bf commit 155fc5e

File tree

5 files changed

+104
-56
lines changed

5 files changed

+104
-56
lines changed

apps/webapp/app/presenters/v3/SpanPresenter.server.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,7 @@ export class SpanPresenter extends BasePresenter {
451451
spanId: true,
452452
createdAt: true,
453453
number: true,
454-
lockedToVersion: {
455-
select: {
456-
version: true,
457-
},
458-
},
454+
taskVersion: true,
459455
},
460456
where: {
461457
parentSpanId: spanId,

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ function SpanEntity({ span }: { span: Span }) {
10811081
{run.taskIdentifier}
10821082
</TableCell>
10831083
<TableCell to={path} actionClassName="py-1.5" rowHoverStyle="bright">
1084-
{run.lockedToVersion?.version ?? "–"}
1084+
{run.taskVersion ?? "–"}
10851085
</TableCell>
10861086
<TableCell to={path} actionClassName="py-1.5" rowHoverStyle="bright">
10871087
<DateTime date={run.createdAt} />

apps/webapp/app/v3/clickhouseEventRepository.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
RunPreparedEvent,
1212
TaskEventRecord,
1313
ExceptionEventProperties,
14+
SpanDetail,
1415
} from "./eventRepository.types";
1516
import type { TaskEventStoreTable } from "./taskEventStore.server";
1617
import type { DynamicFlushScheduler } from "./dynamicFlushScheduler.server";
@@ -155,7 +156,7 @@ export class ClickhouseEventRepository implements IEventRepository {
155156
startCreatedAt: Date,
156157
endCreatedAt?: Date,
157158
options?: { includeDebugLogs?: boolean }
158-
): Promise<any> {
159+
): Promise<SpanDetail | undefined> {
159160
throw new Error("ClickhouseEventRepository.getSpan not implemented");
160161
}
161162

apps/webapp/app/v3/eventRepository.server.ts

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import type {
5757
SpanDetailedSummary,
5858
TraceDetailedSummary,
5959
UpdateEventOptions,
60+
SpanDetail,
6061
} from "./eventRepository.types";
6162
import { DetailedTraceEvent, TaskEventStore, TaskEventStoreTable } from "./taskEventStore.server";
6263
import { startActiveSpan } from "./tracer.server";
@@ -827,50 +828,10 @@ export class EventRepository implements IEventRepository {
827828
endCreatedAt
828829
);
829830

830-
const output = rehydrateJson(spanEvent.output);
831-
const payload = rehydrateJson(spanEvent.payload);
832-
833831
const show = rehydrateShow(spanEvent.properties);
834832

835833
const properties = sanitizedAttributes(spanEvent.properties);
836834

837-
const messagingEvent = SpanMessagingEvent.optional().safeParse(
838-
(properties as any)?.messaging
839-
);
840-
841-
const links: SpanLink[] = [];
842-
843-
if (messagingEvent.success && messagingEvent.data) {
844-
if (messagingEvent.data.message && "id" in messagingEvent.data.message) {
845-
if (messagingEvent.data.message.id.startsWith("run_")) {
846-
links.push({
847-
type: "run",
848-
icon: "runs",
849-
title: `Run ${messagingEvent.data.message.id}`,
850-
runId: messagingEvent.data.message.id,
851-
});
852-
}
853-
}
854-
}
855-
856-
const backLinks = spanEvent.links as any as Link[] | undefined;
857-
858-
if (backLinks && backLinks.length > 0) {
859-
backLinks.forEach((l) => {
860-
const title = String(
861-
l.attributes?.[SemanticInternalAttributes.LINK_TITLE] ?? "Triggered by"
862-
);
863-
864-
links.push({
865-
type: "span",
866-
icon: "trigger",
867-
title,
868-
traceId: l.context.traceId,
869-
spanId: l.context.spanId,
870-
});
871-
});
872-
}
873-
874835
const spanEvents = transformEvents(
875836
span.data.events,
876837
spanEvent.metadata as Attributes,
@@ -891,16 +852,41 @@ export class EventRepository implements IEventRepository {
891852
};
892853

893854
return {
894-
...spanEvent,
895-
...span.data,
896-
payload,
897-
output,
898-
properties,
855+
// Core Identity & Structure
856+
spanId: spanEvent.spanId,
857+
parentId: spanEvent.parentId,
858+
message: spanEvent.message,
859+
860+
// Status & State
861+
isError: span.data.isError,
862+
isPartial: span.data.isPartial,
863+
isCancelled: span.data.isCancelled,
864+
level: spanEvent.level,
865+
kind: spanEvent.kind,
866+
867+
// Timing
868+
startTime: span.data.startTime,
869+
duration: nanosecondsToMilliseconds(span.data.duration),
870+
871+
// Content & Display
899872
events: spanEvents,
900-
show,
901-
links,
902-
originalRun,
873+
style: span.data.style,
874+
properties: properties,
875+
876+
// Context (Used in Span Details)
877+
idempotencyKey: spanEvent.idempotencyKey,
878+
taskSlug: spanEvent.taskSlug,
879+
workerVersion: spanEvent.workerVersion,
880+
881+
// Entity & Relationships
903882
entity,
883+
triggeredRuns: [], // Will be populated by SpanPresenter
884+
showActionBar: show?.actions === true,
885+
886+
// Additional Properties (Used by SpanPresenter)
887+
originalRun,
888+
show,
889+
metadata: spanEvent.metadata,
904890
};
905891
});
906892
}

apps/webapp/app/v3/eventRepository.types.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
Prisma,
1313
TaskEvent,
1414
TaskEventKind,
15+
TaskEventLevel,
1516
TaskEventStatus,
1617
TaskRun,
1718
} from "@trigger.dev/database";
@@ -181,6 +182,70 @@ export type RunPreparedEvent = PreparedEvent & {
181182
taskSlug?: string;
182183
};
183184

185+
export type SpanDetail = {
186+
// ============================================================================
187+
// Core Identity & Structure
188+
// ============================================================================
189+
spanId: string; // Tree structure, span identification
190+
parentId: string | null; // Tree hierarchy
191+
message: string; // Displayed as span title
192+
193+
// ============================================================================
194+
// Status & State
195+
// ============================================================================
196+
isError: boolean; // Error status display, filtering, status icons
197+
isPartial: boolean; // In-progress status display, timeline calculations
198+
isCancelled: boolean; // Cancelled status display, status determination
199+
level: TaskEventLevel; // Text styling, timeline rendering decisions
200+
kind: TaskEventKind; // Filter "UNSPECIFIED" events, determine debug status
201+
202+
// ============================================================================
203+
// Timing
204+
// ============================================================================
205+
startTime: Date; // Timeline calculations, display
206+
duration: number; // Timeline width, duration display, calculations
207+
208+
// ============================================================================
209+
// Content & Display
210+
// ============================================================================
211+
events: SpanEvents; // Timeline events, SpanEvents component
212+
style: TaskEventStyle; // Icons, variants, accessories (RunIcon, SpanTitle)
213+
properties: Record<string, unknown> | string | number | boolean | null | undefined; // Displayed as JSON in span properties (CodeBlock)
214+
215+
// ============================================================================
216+
// Context (Used in Span Details)
217+
// ============================================================================
218+
idempotencyKey: string | null; // Displayed in span detail properties (conditional)
219+
taskSlug: string; // Displayed in span details, task filtering
220+
workerVersion: string | null; // Displayed in span version field
221+
222+
// ============================================================================
223+
// Entity & Relationships
224+
// ============================================================================
225+
entity: {
226+
// Used for entity type switching in SpanEntity
227+
type: string | undefined;
228+
id: string | undefined;
229+
};
230+
triggeredRuns: Array<{
231+
// Used in triggered runs table
232+
friendlyId: string;
233+
taskIdentifier: string;
234+
spanId: string;
235+
createdAt: Date;
236+
number: number;
237+
lockedToVersion?: { version: string };
238+
}>;
239+
showActionBar: boolean; // Computed from show.actions, used for action display
240+
241+
// ============================================================================
242+
// Additional Properties (Used by SpanPresenter)
243+
// ============================================================================
244+
originalRun: string | undefined; // Used by SpanPresenter for run lookup
245+
show: { actions?: boolean } | undefined; // Used by SpanPresenter to compute showActionBar
246+
metadata: any; // Used by SpanPresenter for entity processing
247+
};
248+
184249
// ============================================================================
185250
// Span and Link Types
186251
// ============================================================================
@@ -344,7 +409,7 @@ export interface IEventRepository {
344409
startCreatedAt: Date,
345410
endCreatedAt?: Date,
346411
options?: { includeDebugLogs?: boolean }
347-
): Promise<any>;
412+
): Promise<SpanDetail | undefined>;
348413

349414
// Event recording methods
350415
recordEvent(

0 commit comments

Comments
 (0)