Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crwa): Fix failure in case of disabled telemetry #8062

Merged
merged 16 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ async function createRedwoodApp() {
.parse()

// Record some of the arguments for telemetry
trace.getActiveSpan().setAttribute('yarn-install', yarnInstall)
trace.getActiveSpan().setAttribute('overwrite', overwrite)
trace.getActiveSpan().setAttribute('yarn1', yarn1)
trace.getActiveSpan()?.setAttribute('yarn-install', yarnInstall)
trace.getActiveSpan()?.setAttribute('overwrite', overwrite)
trace.getActiveSpan()?.setAttribute('yarn1', yarn1)

// Get the directory for installation from the args
const targetDir = String(args).replace(/,/g, '-')
Expand Down Expand Up @@ -544,11 +544,11 @@ async function createRedwoodApp() {

// Determine ts/js preference
const useTypescript = await handleTypescriptPreference(typescriptFlag)
trace.getActiveSpan().setAttribute('typescript', useTypescript)
trace.getActiveSpan()?.setAttribute('typescript', useTypescript)

// Determine git preference
const useGit = await handleGitPreference(gitInitFlag)
trace.getActiveSpan().setAttribute('git', useGit)
trace.getActiveSpan()?.setAttribute('git', useGit)

// Create project files
await createProjectFiles(newAppDir, overwrite, yarn1)
Expand All @@ -559,7 +559,7 @@ async function createRedwoodApp() {
await installNodeModules(newAppDir)
trace
.getActiveSpan()
.setAttribute('yarn-install-time', Date.now() - yarnInstallStart)
?.setAttribute('yarn-install-time', Date.now() - yarnInstallStart)
} else {
tui.drawText(
`${RedwoodStyling.warning(
Expand Down Expand Up @@ -671,8 +671,8 @@ async function createRedwoodApp() {
await createRedwoodApp()

// Span housekeeping
span.setStatus({ code: SpanStatusCode.OK })
span.end()
span?.setStatus({ code: SpanStatusCode.OK })
span?.end()
})

// Shutdown telemetry, ensures data is sent before the process exits
Expand Down
4 changes: 2 additions & 2 deletions packages/create-redwood-app/src/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ export async function shutdownTelemetry() {
}

export function recordErrorViaTelemetry(error) {
opentelemetry.trace.getActiveSpan().setStatus({
opentelemetry.trace.getActiveSpan()?.setStatus({
code: SpanStatusCode.ERROR,
message: error.toString().split('\n')[0],
})
opentelemetry.trace.getActiveSpan().recordException(error)
opentelemetry.trace.getActiveSpan()?.recordException(error)
}