From 892cae559909827ec0faa9c9a29e710b7a62b659 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Mon, 11 Sep 2023 17:47:02 +0800 Subject: [PATCH] fix: SHOULD_REPORT_TRACE condition (#4273) Co-authored-by: X1a0t <405028157@qq.com> --- apps/core/.webpack/config.ts | 10 ++++++---- apps/prototype/vite.config.ts | 2 +- apps/storybook/.storybook/main.ts | 2 +- packages/graphql/src/utils.ts | 13 ++++++++----- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/core/.webpack/config.ts b/apps/core/.webpack/config.ts index 2a18ad9782..d5e9c646f4 100644 --- a/apps/core/.webpack/config.ts +++ b/apps/core/.webpack/config.ts @@ -349,10 +349,12 @@ export const createConfiguration: ( 'process.env': JSON.stringify({}), 'process.env.COVERAGE': JSON.stringify(!!buildFlags.coverage), 'process.env.NODE_ENV': JSON.stringify(buildFlags.mode), - 'process.env.SHOULD_REPORT_TRACE': `${Boolean( - process.env.SHOULD_REPORT_TRACE - )}`, - 'process.env.TRACE_REPORT_ENDPOINT': `"${process.env.TRACE_REPORT_ENDPOINT}"`, + 'process.env.SHOULD_REPORT_TRACE': JSON.stringify( + Boolean(process.env.SHOULD_REPORT_TRACE === 'true') + ), + 'process.env.TRACE_REPORT_ENDPOINT': JSON.stringify( + process.env.TRACE_REPORT_ENDPOINT + ), runtimeConfig: JSON.stringify(runtimeConfig), }), new CopyPlugin({ diff --git a/apps/prototype/vite.config.ts b/apps/prototype/vite.config.ts index d39904944f..24f4c53e50 100644 --- a/apps/prototype/vite.config.ts +++ b/apps/prototype/vite.config.ts @@ -24,7 +24,7 @@ export default defineConfig({ 'process.env': {}, 'process.env.COVERAGE': JSON.stringify(!!process.env.COVERAGE), 'process.env.SHOULD_REPORT_TRACE': `${Boolean( - process.env.SHOULD_REPORT_TRACE + process.env.SHOULD_REPORT_TRACE === 'true' )}`, 'process.env.TRACE_REPORT_ENDPOINT': `"${process.env.TRACE_REPORT_ENDPOINT}"`, runtimeConfig: getRuntimeConfig({ diff --git a/apps/storybook/.storybook/main.ts b/apps/storybook/.storybook/main.ts index 677ab6b00e..28d364219f 100644 --- a/apps/storybook/.storybook/main.ts +++ b/apps/storybook/.storybook/main.ts @@ -47,7 +47,7 @@ export default { 'process.env': {}, 'process.env.COVERAGE': JSON.stringify(!!process.env.COVERAGE), 'process.env.SHOULD_REPORT_TRACE': `${Boolean( - process.env.SHOULD_REPORT_TRACE + process.env.SHOULD_REPORT_TRACE === 'true' )}`, 'process.env.TRACE_REPORT_ENDPOINT': `"${process.env.TRACE_REPORT_ENDPOINT}"`, runtimeConfig: getRuntimeConfig({ diff --git a/packages/graphql/src/utils.ts b/packages/graphql/src/utils.ts index 7561821253..fb9804c504 100644 --- a/packages/graphql/src/utils.ts +++ b/packages/graphql/src/utils.ts @@ -49,8 +49,7 @@ export function generateRandUTF16Chars(bytes: number) { } export class TraceReporter { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - static traceReportEndpoint = process.env.TRACE_REPORT_ENDPOINT!; + static traceReportEndpoint = process.env.TRACE_REPORT_ENDPOINT; static shouldReportTrace = process.env.SHOULD_REPORT_TRACE; private spansCache = new Array(); @@ -108,6 +107,10 @@ export class TraceReporter { } public static reportToTraceEndpoint(payload: string): void { + if (!TraceReporter.traceReportEndpoint) { + console.warn('No trace report endpoint found!'); + return; + } if (typeof navigator !== 'undefined') { navigator.sendBeacon(TraceReporter.traceReportEndpoint, payload); } else { @@ -201,6 +204,6 @@ export class TraceReporter { }; } -export const traceReporter = !process.env.SHOULD_REPORT_TRACE - ? null - : TraceReporter.getInstance(); +export const traceReporter = process.env.SHOULD_REPORT_TRACE + ? TraceReporter.getInstance() + : null;