diff --git a/src/lib/instrumentation.ts b/src/lib/instrumentation.ts index 59e5924..9a6db55 100644 --- a/src/lib/instrumentation.ts +++ b/src/lib/instrumentation.ts @@ -1,6 +1,7 @@ import logger from "../logger.js"; import { getBrowserStackAuth } from "./get-auth.js"; import { createRequire } from "module"; +import { detectRunMode } from "./utils.js"; const require = createRequire(import.meta.url); const packageJson = require("../../package.json"); import axios from "axios"; @@ -12,6 +13,7 @@ interface MCPEventPayload { tool_name: string; mcp_client: string; success?: boolean; + mode?: string; error_message?: string; error_type?: string; }; @@ -53,7 +55,9 @@ export function trackMCP( event.event_properties.error_type = error instanceof Error ? error.constructor.name : "Unknown"; } - + + event.event_properties.mode = detectRunMode(); + let authHeader = undefined; if (config) { const authString = getBrowserStackAuth(config); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index e19532c..c03f7c7 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,4 +1,6 @@ import sharp from "sharp"; +import path from "path"; +import { fileURLToPath } from "url"; import type { ApiResponse } from "./apiClient.js"; export function sanitizeUrlParam(param: string): string { @@ -38,3 +40,14 @@ export async function assertOkResponse( ); } } + +export function detectRunMode(): "npx" | "local" | "unknown" { + try { + const scriptPath = fileURLToPath(import.meta.url); + const normalizedPath = path.normalize(scriptPath); + const npxPattern = path.sep + "_npx" + path.sep; + return normalizedPath.includes(npxPattern) ? "npx" : "local"; + } catch { + return "unknown"; + } +}