find_slow_requests
Search Tempo datasources to identify slow requests within specified time ranges and labels for performance analysis.
Instructions
Searches relevant Tempo datasources for slow requests and returns the results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | End time for the investigation | |
| labels | Yes | Labels to scope the analysis | |
| name | Yes | The name of the investigation | |
| start | No | Start time for the investigation |
Implementation Reference
- src/tools/sift.ts:131-168 (handler)The handler function for the 'find_slow_requests' tool. It creates a Sift investigation for slow requests using the provided parameters, posts it to the API, polls for results, and returns the investigation details.handler: async (params, context: ToolContext) => { try { const client = createSiftClient(context.config.grafanaConfig); // Create investigation const investigationData = { name: params.name, start: params.start || new Date(Date.now() - 30 * 60 * 1000).toISOString(), end: params.end || new Date().toISOString(), labels: params.labels, analyses: [ { type: 'slow_requests', parameters: { labels: params.labels, }, }, ], }; const response = await client.post('/api/v1/investigations', investigationData); const investigationId = response.data.id; // Poll for results (simplified - real implementation would need proper polling) await new Promise(resolve => setTimeout(resolve, 5000)); const resultResponse = await client.get(`/api/v1/investigations/${investigationId}`); return createToolResult({ investigationId, status: resultResponse.data.status, analyses: resultResponse.data.analyses, message: 'Investigation started. Check status for results.', }); } catch (error: any) { return createErrorResult(error.response?.data?.message || error.message); } },
- src/tools/sift.ts:19-24 (schema)Zod input schema for the 'find_slow_requests' tool defining parameters like name, labels, start, and end times.const FindSlowRequestsSchema = z.object({ name: z.string().describe('The name of the investigation'), labels: z.record(z.string()).describe('Labels to scope the analysis'), start: z.string().optional().describe('Start time for the investigation'), end: z.string().optional().describe('End time for the investigation'), });
- src/tools/sift.ts:215-220 (registration)The registration function that registers the 'find_slow_requests' tool (and other Sift tools) with the MCP server.export function registerSiftTools(server: any) { server.registerTool(listSiftInvestigations); server.registerTool(getSiftInvestigation); server.registerTool(getSiftAnalysis); server.registerTool(findSlowRequests); server.registerTool(findErrorPatternLogs);
- src/tools/sift.ts:34-57 (helper)Helper function to create an axios client configured for the Sift API, used by the find_slow_requests handler.function createSiftClient(config: any) { const headers: any = { 'User-Agent': 'mcp-grafana/1.0.0', 'Content-Type': 'application/json', }; if (config.serviceAccountToken) { headers['Authorization'] = `Bearer ${config.serviceAccountToken}`; } else if (config.apiKey) { headers['Authorization'] = `Bearer ${config.apiKey}`; } // Sift uses a different base URL pattern const baseUrl = config.url.replace(/\/$/, ''); const siftUrl = baseUrl.includes('grafana.net') ? baseUrl.replace('grafana.net', 'sift.grafana.net') : `${baseUrl}/api/plugins/grafana-sift-app/resources`; return axios.create({ baseURL: siftUrl, headers, timeout: 60000, // Longer timeout for investigations }); }
- src/tools/sift.ts:127-169 (handler)Full ToolDefinition export for 'find_slow_requests', including name, description, schema reference, and handler.export const findSlowRequests: ToolDefinition = { name: 'find_slow_requests', description: 'Searches relevant Tempo datasources for slow requests and returns the results', inputSchema: FindSlowRequestsSchema, handler: async (params, context: ToolContext) => { try { const client = createSiftClient(context.config.grafanaConfig); // Create investigation const investigationData = { name: params.name, start: params.start || new Date(Date.now() - 30 * 60 * 1000).toISOString(), end: params.end || new Date().toISOString(), labels: params.labels, analyses: [ { type: 'slow_requests', parameters: { labels: params.labels, }, }, ], }; const response = await client.post('/api/v1/investigations', investigationData); const investigationId = response.data.id; // Poll for results (simplified - real implementation would need proper polling) await new Promise(resolve => setTimeout(resolve, 5000)); const resultResponse = await client.get(`/api/v1/investigations/${investigationId}`); return createToolResult({ investigationId, status: resultResponse.data.status, analyses: resultResponse.data.analyses, message: 'Investigation started. Check status for results.', }); } catch (error: any) { return createErrorResult(error.response?.data?.message || error.message); } }, };