fix: SHOULD_REPORT_TRACE condition (#4273)

Co-authored-by: X1a0t <405028157@qq.com>
This commit is contained in:
Peng Xiao 2023-09-11 17:47:02 +08:00 committed by GitHub
parent a25a31c105
commit 892cae5599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 11 deletions

View File

@ -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({

View File

@ -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({

View File

@ -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({

View File

@ -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<TraceSpan>();
@ -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;