diff --git a/apps/webapp/app/v3/eventRepository.server.ts b/apps/webapp/app/v3/eventRepository.server.ts index 8c94f44e2..b81474ef4 100644 --- a/apps/webapp/app/v3/eventRepository.server.ts +++ b/apps/webapp/app/v3/eventRepository.server.ts @@ -415,6 +415,7 @@ export class EventRepository { }, select: { traceId: true, + environmentType: true, }, }); @@ -493,7 +494,11 @@ export class EventRepository { }); } - const events = transformEvents(span.data.events, fullEvent.metadata as Attributes); + const events = transformEvents( + span.data.events, + fullEvent.metadata as Attributes, + traceSearch.environmentType === "DEVELOPMENT" + ); return { ...fullEvent, @@ -1115,16 +1120,16 @@ function removePrivateProperties( return result; } -function transformEvents(events: SpanEvents, properties: Attributes): SpanEvents { - return (events ?? []).map((event) => transformEvent(event, properties)); +function transformEvents(events: SpanEvents, properties: Attributes, isDev: boolean): SpanEvents { + return (events ?? []).map((event) => transformEvent(event, properties, isDev)); } -function transformEvent(event: SpanEvent, properties: Attributes): SpanEvent { +function transformEvent(event: SpanEvent, properties: Attributes, isDev: boolean): SpanEvent { if (isExceptionSpanEvent(event)) { return { ...event, properties: { - exception: transformException(event.properties.exception, properties), + exception: transformException(event.properties.exception, properties, isDev), }, }; } @@ -1134,11 +1139,12 @@ function transformEvent(event: SpanEvent, properties: Attributes): SpanEvent { function transformException( exception: ExceptionEventProperties, - properties: Attributes + properties: Attributes, + isDev: boolean ): ExceptionEventProperties { const projectDirAttributeValue = properties[SemanticInternalAttributes.PROJECT_DIR]; - if (typeof projectDirAttributeValue !== "string") { + if (projectDirAttributeValue !== undefined && typeof projectDirAttributeValue !== "string") { return exception; } @@ -1147,6 +1153,7 @@ function transformException( stacktrace: exception.stacktrace ? correctErrorStackTrace(exception.stacktrace, projectDirAttributeValue, { removeFirstLine: true, + isDev, }) : undefined, }; diff --git a/packages/core/src/v3/errors.ts b/packages/core/src/v3/errors.ts index c9a1e1551..aa2481da9 100644 --- a/packages/core/src/v3/errors.ts +++ b/packages/core/src/v3/errors.ts @@ -57,13 +57,13 @@ export function createErrorTaskError(error: TaskRunError): any { export function correctErrorStackTrace( stackTrace: string, projectDir?: string, - options?: { removeFirstLine?: boolean } + options?: { removeFirstLine?: boolean; isDev?: boolean } ) { const [errorLine, ...traceLines] = stackTrace.split("\n"); return [ options?.removeFirstLine ? undefined : errorLine, - ...traceLines.map((line) => correctStackTraceLine(line, projectDir)), + ...traceLines.map((line) => correctStackTraceLine(line, projectDir, options?.isDev)), ] .filter(Boolean) .join("\n"); @@ -75,17 +75,21 @@ const LINES_TO_IGNORE = [ /TaskExecutor/, /EXECUTE_TASK_RUN/, /@trigger.dev\/core/, + /packages\/core\/src\/v3/, /safeJsonProcess/, /__entryPoint.ts/, + /ZodIpc/, + /startActiveSpan/, + /processTicksAndRejections/, ]; -function correctStackTraceLine(line: string, projectDir?: string) { +function correctStackTraceLine(line: string, projectDir?: string, isDev?: boolean) { if (LINES_TO_IGNORE.some((regex) => regex.test(line))) { return; } // Check to see if the path is inside the project directory - if (projectDir && !line.includes(projectDir)) { + if (isDev && projectDir && !line.includes(projectDir)) { return; }