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
22 changes: 21 additions & 1 deletion apps/webapp/app/v3/eventRepository/eventRepository.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import type {
RunPreparedEvent,
SpanDetail,
SpanDetailedSummary,
SpanOverride,
SpanSummary,
TraceAttributes,
TraceDetailedSummary,
Expand Down Expand Up @@ -428,6 +429,7 @@ export class EventRepository implements IEventRepository {
return await startActiveSpan("getTraceSummary", async (span) => {
const events = await this.taskEventStore.findTraceEvents(
storeTable,
environmentId,
traceId,
startCreatedAt,
endCreatedAt,
Expand Down Expand Up @@ -479,6 +481,7 @@ export class EventRepository implements IEventRepository {
preparedEvents = Array.from(eventsBySpanId.values());

const spansBySpanId = new Map<string, SpanSummary>();
const overridesBySpanId: Record<string, SpanOverride> = {};

const spans = preparedEvents.map((event) => {
const overrides = getAncestorOverrides({
Expand All @@ -499,6 +502,14 @@ export class EventRepository implements IEventRepository {
? overrides.isError
: event.isError;

if (overrides) {
const spanOverride: SpanOverride = {};
if (overrides.isCancelled) spanOverride.isCancelled = true;
if (overrides.isError) spanOverride.isError = true;
if (overrides.duration !== undefined) spanOverride.duration = overrides.duration;
overridesBySpanId[event.spanId] = spanOverride;
}

const span = {
id: event.spanId,
parentId: event.parentId ?? undefined,
Expand Down Expand Up @@ -535,6 +546,7 @@ export class EventRepository implements IEventRepository {
return {
rootSpan,
spans,
overridesBySpanId,
};
});
}
Expand Down Expand Up @@ -747,6 +759,7 @@ export class EventRepository implements IEventRepository {
const spanEvent = await this.#getSpanEvent({
storeTable,
spanId,
traceId,
environmentId,
startCreatedAt,
endCreatedAt,
Expand Down Expand Up @@ -972,22 +985,29 @@ export class EventRepository implements IEventRepository {
async #getSpanEvent({
storeTable,
spanId,
traceId,
environmentId,
startCreatedAt,
endCreatedAt,
options,
}: {
storeTable: TaskEventStoreTable;
spanId: string;
traceId?: string;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: traceId is optional in #getSpanEvent, so ancestor traversal still performs unscoped span lookups. This can attach parents from another trace when span IDs collide, producing incorrect span status and duration overrides.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/webapp/app/v3/eventRepository/eventRepository.server.ts, line 996:

<comment>`traceId` is optional in `#getSpanEvent`, so ancestor traversal still performs unscoped span lookups. This can attach parents from another trace when span IDs collide, producing incorrect span status and duration overrides.</comment>

<file context>
@@ -972,22 +985,29 @@ export class EventRepository implements IEventRepository {
   }: {
     storeTable: TaskEventStoreTable;
     spanId: string;
+    traceId?: string;
     environmentId: string;
     startCreatedAt: Date;
</file context>

environmentId: string;
startCreatedAt: Date;
endCreatedAt?: Date;
options?: { includeDebugLogs?: boolean };
}) {
return await startActiveSpan("getSpanEvent", async (s) => {
const where: Prisma.TaskEventWhereInput = { spanId, environmentId };
if (traceId) {
where.traceId = traceId;
}

const events = await this.taskEventStore.findMany(
storeTable,
{ spanId, environmentId },
where,
startCreatedAt,
endCreatedAt,
undefined,
Expand Down
3 changes: 3 additions & 0 deletions apps/webapp/app/v3/taskEventStore.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class TaskEventStore {

async findTraceEvents(
table: TaskEventStoreTable,
environmentId: string,
traceId: string,
startCreatedAt: Date,
endCreatedAt?: Date,
Expand Down Expand Up @@ -184,6 +185,7 @@ export class TaskEventStore {
FROM "TaskEventPartitioned"
WHERE
"traceId" = ${traceId}
AND "environmentId" = ${environmentId}
AND "createdAt" >= ${startCreatedAtWithBuffer.toISOString()}::timestamp
AND "createdAt" < ${endCreatedAtWithBuffer.toISOString()}::timestamp
${
Expand Down Expand Up @@ -214,6 +216,7 @@ export class TaskEventStore {
"attemptNumber"
FROM "TaskEvent"
WHERE "traceId" = ${traceId}
AND "environmentId" = ${environmentId}
${
filterDebug
? Prisma.sql`AND \"kind\" <> CAST('LOG'::text AS "public"."TaskEventKind")`
Expand Down
Loading