Skip to content

Commit

Permalink
add missing execute metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya committed Nov 23, 2023
1 parent 0bb0791 commit 3ce1520
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
19 changes: 3 additions & 16 deletions src/commands/generate/fromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 2 additions & 16 deletions src/commands/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3ce1520

Please sign in to comment.