Skip to content

feat : O11Y Failure Logs #59

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

Closed
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"axios": "^1.8.4",
"browserstack-local": "^1.5.6",
"csv-parse": "^5.6.0",
"date-fns": "^4.1.0",
"dotenv": "^16.5.0",
"form-data": "^4.0.2",
"pino": "^9.6.0",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import addAppAutomationTools from "./tools/appautomate.js";
import addFailureLogsTools from "./tools/getFailureLogs.js";
import addAutomateTools from "./tools/automate.js";
import addSelfHealTools from "./tools/selfheal.js";
import addAnalyseTestFailureTools from "./tools/analyse-test-failure.js";
import { setupOnInitialized } from "./oninitialized.js";

function registerTools(server: McpServer) {
Expand All @@ -28,6 +29,7 @@ function registerTools(server: McpServer) {
addFailureLogsTools(server);
addAutomateTools(server);
addSelfHealTools(server);
addAnalyseTestFailureTools(server);
}

// Create an MCP server
Expand Down
16 changes: 16 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ export const AppAutomateLogType = {
CrashLogs: "crashLogs",
} as const;

export const BrowserstackLogTypes = {
Network: "network",
Session: "session",
Text: "text",
Console: "console",
Selenium: "selenium",
Appium: "appium",
Device: "device",
Crash: "crash",
Playwright: "playwright",
Telemetry: "telemetry",
Performance: "performance",
Terminal: "terminal",
BrowserProfiling: "browserProfiling",
} as const;

export type SessionType = (typeof SessionType)[keyof typeof SessionType];
export type AutomateLogType =
(typeof AutomateLogType)[keyof typeof AutomateLogType];
Expand Down
61 changes: 61 additions & 0 deletions src/tools/analyse-test-failure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import logger from "../logger.js";
import { retrieveTestObservabilityLogs } from "./testfailurelogs-utils/o11y-logs.js";
import { retrieveObservabilityTestCase } from "./testfailurelogs-utils/test-case.js";
import { trackMCP } from "../lib/instrumentation.js";

export async function analyseTestFailure(args: {
testId: string;
}): Promise<CallToolResult> {
try {
const failureLogs = await retrieveTestObservabilityLogs(args.testId);
const testCase = await retrieveObservabilityTestCase(args.testId);

const response = {
failure_logs: failureLogs,
test_case: testCase,
};

return {
content: [
{
type: "text",
text: JSON.stringify(response, null, 2),
},
],
};
} catch (error) {
logger.error("Error during analysing the test ID", error);
throw error;
}
}

export default function addAnalyseTestFailureTool(server: McpServer) {
server.tool(
"analyseTestFailure",
"Use this tool to analyse a failed test-id from BrowserStack Test Reporting and Analytics",
{
testId: z.string().describe("The BrowserStack test ID to analyse"),
},
async (args) => {
try {
trackMCP("analyseTestFailure", server.server.getClientVersion()!);
return await analyseTestFailure(args);
} catch (error) {
trackMCP("analyseTestFailure", server.server.getClientVersion()!);
const errorMessage =
error instanceof Error ? error.message : "Unknown error";
return {
content: [
{
type: "text",
text: `Error during analysing test ID: ${errorMessage}`,
},
],
};
}
},
);
}
77 changes: 77 additions & 0 deletions src/tools/failurelogs-utils/automate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,80 @@ export function filterConsoleFailures(logText: string): string[] {
];
return filterLinesByKeywords(logText, keywords);
}

export function filterSDKFailures(logText: string): string[] {
const keywords = [
"fail",
"error",
"exception",
"fatal",
"unable to",
"not found",
"timeout",
"crash",
"rejected",
"denied",
"broken",
"unsuccessful",
"panic",
];
return filterLinesByKeywords(logText, keywords);
}

export function filterHookRunFailures(logText: string): string[] {
const keywords = [
"except block error",
"unable to",
"cannot find module",
"doesn't exist",
"error while loading",
"error:",
"failed to",
"not found",
"missing",
"rejected",
"no such file",
"npm ERR!",
"stderr",
"fatal",
];

return filterLinesByKeywords(logText, keywords);
}

export function filterSeleniumFailures(logText: string): string[] {
const keywords = [
"NoSuchElementException",
"TimeoutException",
"StaleElementReferenceException",
"ElementNotInteractableException",
"ElementClickInterceptedException",
"InvalidSelectorException",
"SessionNotCreatedException",
"InvalidSessionIdException",
"WebDriverException",
"error",
"exception",
"fail"
];
return filterLinesByKeywords(logText, keywords);
}


export function filterPlaywrightFailures(logText: string): string[] {
const keywords = [
"TimeoutError",
"page crashed",
"browser closed",
"navigation timeout",
"element handle is detached",
"protocol error",
"execution context was destroyed",
"strict mode violation",
"network error",
"error",
"exception",
"fail"
];
return filterLinesByKeywords(logText, keywords);
}
Loading