🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: support non ascii characters in exports (#10931)
Max Deichmann1647e080b5eb
diff --git a/packages/shared/src/features/batchExport/types.ts b/packages/shared/src/features/batchExport/types.tsindex ebabc57bb2..44a38bc723 100644--- a/packages/shared/src/features/batchExport/types.ts+++ b/packages/shared/src/features/batchExport/types.ts@@ -33,12 +33,16 @@ export const exportOptions: Record<fileType: string;}> = {- CSV: { label: "CSV", extension: "csv", fileType: "text/csv" },- JSON: { label: "JSON", extension: "json", fileType: "application/json" },+ CSV: { label: "CSV", extension: "csv", fileType: "text/csv; charset=utf-8" },+ JSON: {+ label: "JSON",+ extension: "json",+ fileType: "application/json; charset=utf-8",+ },JSONL: {label: "JSONL",extension: "jsonl",- fileType: "application/x-ndjson",+ fileType: "application/x-ndjson; charset=utf-8",},} as const;diff --git a/web/src/components/session/index.tsx b/web/src/components/session/index.tsxindex 0df319fc2b..579cb6c708 100644--- a/web/src/components/session/index.tsx+++ b/web/src/components/session/index.tsx@@ -203,7 +203,9 @@ export const SessionPage: React.FC<{};const jsonString = JSON.stringify(exportData, null, 2);- const blob = new Blob([jsonString], { type: "application/json" });+ const blob = new Blob([jsonString], {+ type: "application/json; charset=utf-8",+ });const url = URL.createObjectURL(blob);const link = document.createElement("a");diff --git a/web/src/components/trace/index.tsx b/web/src/components/trace/index.tsxindex 62861b2ec2..a206e1cb9e 100644--- a/web/src/components/trace/index.tsx+++ b/web/src/components/trace/index.tsx@@ -293,7 +293,9 @@ export function Trace(props: {};const jsonString = JSON.stringify(exportData, null, 2);- const blob = new Blob([jsonString], { type: "application/json" });+ const blob = new Blob([jsonString], {+ type: "application/json; charset=utf-8",+ });const url = URL.createObjectURL(blob);const link = document.createElement("a");diff --git a/web/src/components/trace/lib/helpers.ts b/web/src/components/trace/lib/helpers.tsindex 17bfa4984c..14e1f046cd 100644--- a/web/src/components/trace/lib/helpers.ts+++ b/web/src/components/trace/lib/helpers.ts@@ -455,7 +455,9 @@ export function downloadTraceAsJson(params: {};const jsonString = JSON.stringify(exportData, null, 2);- const blob = new Blob([jsonString], { type: "application/json" });+ const blob = new Blob([jsonString], {+ type: "application/json; charset=utf-8",+ });const url = URL.createObjectURL(blob);const link = document.createElement("a");diff --git a/web/src/components/trace2/lib/download-trace.ts b/web/src/components/trace2/lib/download-trace.tsindex b4392f5d2a..4730d6aaa2 100644--- a/web/src/components/trace2/lib/download-trace.ts+++ b/web/src/components/trace2/lib/download-trace.ts@@ -28,7 +28,9 @@ export function downloadTraceAsJson(params: DownloadTraceAsJsonParams): void {};const jsonString = JSON.stringify(exportData, null, 2);- const blob = new Blob([jsonString], { type: "application/json" });+ const blob = new Blob([jsonString], {+ type: "application/json; charset=utf-8",+ });const url = URL.createObjectURL(blob);const link = document.createElement("a");diff --git a/web/src/components/trace2/lib/helpers.ts b/web/src/components/trace2/lib/helpers.tsindex d35badf2b5..dde369f220 100644--- a/web/src/components/trace2/lib/helpers.ts+++ b/web/src/components/trace2/lib/helpers.ts@@ -492,7 +492,9 @@ export function downloadTraceAsJson(params: {};const jsonString = JSON.stringify(exportData, null, 2);- const blob = new Blob([jsonString], { type: "application/json" });+ const blob = new Blob([jsonString], {+ type: "application/json; charset=utf-8",+ });const url = URL.createObjectURL(blob);const link = document.createElement("a");diff --git a/worker/src/__tests__/batchExport.test.ts b/worker/src/__tests__/batchExport.test.tsindex 31736676a4..0fcc7403af 100644--- a/worker/src/__tests__/batchExport.test.ts+++ b/worker/src/__tests__/batchExport.test.ts@@ -1997,4 +1997,84 @@ describe("batch export test suite", () => {expect(rowsByIdVariant[0].id).toBe("other-trace-id-456");expect(rowsByIdVariant[0].name).toBe("other-trace");});++ it("should properly export traces with Thai and other non-ASCII characters", async () => {+ const { projectId } = await createOrgProjectAndApiKey();++ // Create traces with Thai, Chinese, Arabic, and emoji characters+ const traces = [+ createTrace({+ project_id: projectId,+ name: "สวัสดี ภาษาไทย", // Thai: "Hello Thai language"+ user_id: "ผู้ใช้", // Thai: "user"+ metadata: {+ description: "การทดสอบภาษาไทย", // Thai: "Thai language test"+ mixed: "Hello สวัสดี 世界 مرحبا 🌍",+ },+ tags: ["ไทย", "テスト", "测试"],+ }),+ createTrace({+ project_id: projectId,+ name: "中文测试", // Chinese: "Chinese test"+ user_id: "用户", // Chinese: "user"+ metadata: {+ description: "这是中文测试", // Chinese: "This is a Chinese test"+ },+ tags: ["中文", "汉字"],+ }),+ createTrace({+ project_id: projectId,+ name: "العربية", // Arabic: "Arabic"+ user_id: "مستخدم", // Arabic: "user"+ metadata: {+ description: "اختبار اللغة العربية", // Arabic: "Arabic language test"+ },+ tags: ["عربي"],+ }),+ ];++ await createTracesCh(traces);++ // Export all traces+ const stream = await getTraceStream({+ projectId: projectId,+ cutoffCreatedAt: new Date(Date.now() + 1000 * 60 * 60 * 24),+ filter: [],+ });++ const rows: any[] = [];+ for await (const chunk of stream) {+ rows.push(chunk);+ }++ expect(rows).toHaveLength(3);++ // Verify Thai characters are preserved+ const thaiTrace = rows.find((r) => r.name === "สวัสดี ภาษาไทย");+ expect(thaiTrace).toBeDefined();+ expect(thaiTrace?.userId).toBe("ผู้ใช้");+ expect(thaiTrace?.metadata).toEqual({+ description: "การทดสอบภาษาไทย",+ mixed: "Hello สวัสดี 世界 مرحبا 🌍",+ });+ expect(thaiTrace?.tags).toEqual(["ไทย", "テスト", "测试"]);++ // Verify Chinese characters are preserved+ const chineseTrace = rows.find((r) => r.name === "中文测试");+ expect(chineseTrace).toBeDefined();+ expect(chineseTrace?.userId).toBe("用户");+ expect(chineseTrace?.metadata).toEqual({+ description: "这是中文测试",+ });+ expect(chineseTrace?.tags).toEqual(["中文", "汉字"]);++ // Verify Arabic characters are preserved+ const arabicTrace = rows.find((r) => r.name === "العربية");+ expect(arabicTrace).toBeDefined();+ expect(arabicTrace?.userId).toBe("مستخدم");+ expect(arabicTrace?.metadata).toEqual({+ description: "اختبار اللغة العربية",+ });+ expect(arabicTrace?.tags).toEqual(["عربي"]);+ });});diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.tsindex d6690c3e08..18b0242b0b 100644--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts@@ -123,17 +123,17 @@ const getFileTypeProperties = (fileType: BlobStorageIntegrationFileType) => {switch (fileType) {case BlobStorageIntegrationFileType.JSON:return {- contentType: "application/json",+ contentType: "application/json; charset=utf-8",extension: "json",};case BlobStorageIntegrationFileType.CSV:return {- contentType: "text/csv",+ contentType: "text/csv; charset=utf-8",extension: "csv",};case BlobStorageIntegrationFileType.JSONL:return {- contentType: "application/x-ndjson",+ contentType: "application/x-ndjson; charset=utf-8",extension: "jsonl",};default: