dynamics_get_plugin_performance
Analyze plugin execution performance in Dynamics CRM by tracking duration, errors, and frequency to identify bottlenecks and optimize workflows.
Instructions
Analisa performance de execução de plugins (duração, erros, frequência)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| top | No | Número de plugins a retornar | |
| minDuration | No | Duração mínima em ms para filtrar | |
| entityLogicalName | No | Filtrar por entidade |
Implementation Reference
- src/tools/telemetry/index.ts:85-139 (handler)Implementation of the dynamics_get_plugin_performance tool handler.
server.tool( "dynamics_get_plugin_performance", "Analisa performance de execução de plugins (duração, erros, frequência)", GetPluginPerformanceSchema.shape, async (params: z.infer<typeof GetPluginPerformanceSchema>) => { const filters: string[] = []; if (params.minDuration) { filters.push(`performanceexecutionduration ge ${params.minDuration}`); } if (params.entityLogicalName) { filters.push(`contains(primaryentity,'${params.entityLogicalName}')`); } const result = await client.list("plugintracelogs", { select: [ "typename", "messagename", "primaryentity", "performanceexecutionstarttime", "performanceexecutionduration", "operationtype", "exceptiondetails", "depth", "createdon", "correlationid", "issystemcreated", ], filter: filters.length > 0 ? filters.join(" and ") : undefined, orderby: "performanceexecutionduration desc", top: params.top, }); // Calculate statistics const traces = result.value as Array<Record<string, unknown>>; const stats = { totalExecutions: traces.length, withErrors: traces.filter((t) => t.exceptiondetails).length, avgDuration: traces.length > 0 ? Math.round(traces.reduce((sum, t) => sum + ((t.performanceexecutionduration as number) || 0), 0) / traces.length) : 0, maxDuration: traces.length > 0 ? Math.max(...traces.map((t) => (t.performanceexecutionduration as number) || 0)) : 0, slowestPlugins: traces.slice(0, 5).map((t) => ({ name: t.typename, message: t.messagename, entity: t.primaryentity, duration: t.performanceexecutionduration, hasError: !!t.exceptiondetails, })), }; return { content: [ { type: "text" as const, text: `## Performance de Plugins\n\n**Resumo:**\n- Total de execuções analisadas: ${stats.totalExecutions}\n- Execuções com erro: ${stats.withErrors}\n- Duração média: ${stats.avgDuration}ms\n- Duração máxima: ${stats.maxDuration}ms\n\n**Top 5 Plugins mais lentos:**\n${stats.slowestPlugins.map((p, i) => `${i + 1}. **${p.name}** (${p.message} em ${p.entity}) - ${p.duration}ms ${p.hasError ? "⚠ COM ERRO" : ""}`).join("\n")}\n\n**Detalhes:**\n${JSON.stringify(traces.slice(0, 10), null, 2)}`, }, ], }; } ); - src/tools/telemetry/index.ts:11-15 (schema)Zod schema definition for input validation of the dynamics_get_plugin_performance tool.
export const GetPluginPerformanceSchema = z.object({ top: z.number().default(20).describe("Número de plugins a retornar"), minDuration: z.number().optional().describe("Duração mínima em ms para filtrar"), entityLogicalName: z.string().optional().describe("Filtrar por entidade"), }); - src/tools/telemetry/index.ts:80-83 (registration)Registration of the dynamics_get_plugin_performance tool within registerTelemetryTools.
export function registerTelemetryTools( server: { tool: Function }, client: DataverseClient ) {