resurrect prod stack traces

This commit is contained in:
nicktrn
2024-05-02 16:40:25 +01:00
parent c75bbfdf2c
commit f53004de6b
2 changed files with 22 additions and 11 deletions
+14 -7
View File
@@ -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,
};
+8 -4
View File
@@ -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;
}