diff --git a/src/commands/generate/fromTemplate.ts b/src/commands/generate/fromTemplate.ts index 8df10bdbf80..5486fa34961 100644 --- a/src/commands/generate/fromTemplate.ts +++ b/src/commands/generate/fromTemplate.ts @@ -144,27 +144,14 @@ export default class Template extends Command { this.error(`${template} template does not support AsyncAPI v3 documents, please checkout ${v3IssueLink}`); } } - const result = await this.generate(asyncapi, template, output, options, genOption); + await this.generate(asyncapi, template, output, options, genOption); if (watchTemplate) { const watcherHandler = this.watcherHandler(asyncapi, template, output, options, genOption); await this.runWatchMode(asyncapi, template, output, watcherHandler); } - try { - // Metrics recording. - const {document} = await this.parser.parse(asyncapiInput.text()); - if (document !== undefined && result) { - const metadata = MetadataFromDocument(document); - metadata['success'] = true; - metadata['template'] = template; - await this.recorder.recordActionExecuted('generate_fromTemplate', metadata); - await this.recorder.flush(); - } - } catch (e: any) { - if (e instanceof Error) { - this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`); - } - } + // Metrics recording. + await this.recordActionExecuted('generate_from_template', {success: true, template}, asyncapiInput.text()); } private parseFlags(disableHooks?: string[], params?: string[], mapBaseUrl?: string): ParsedFlags { diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index a49b2199e43..5ea56b39099 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -132,22 +132,8 @@ export default class Optimize extends Command { }); } - try { - // Metrics recording. - const {document} = await this.parser.parse(specFile.text()); - const optimizedDoc = optimizer.getOptimizedDocument(); - if (document !== undefined && optimizedDoc) { - const metadata = MetadataFromDocument(document); - metadata['success'] = true; - metadata['optimizations'] = this.optimizations; - await this.recorder.recordActionExecuted('optimize', metadata); - await this.recorder.flush(); - } - } catch (e: any) { - if (e instanceof Error) { - this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`); - } - } + // Metrics recording. + await this.recordActionExecuted('optimize', {success: true, optimizations: this.optimizations}, specFile.text()); } private showOptimizations(elements: ReportElement[] | undefined) {