Skip to content

Commit

Permalink
fix: js release yml, reduce batch size, change telemetry payload (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit authored Dec 11, 2024
1 parent b98afd5 commit d7b9502
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 41 deletions.
17 changes: 2 additions & 15 deletions .github/workflows/release_js_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ on:

jobs:
run-js-tests:
permissions:
contents: write
timeout-minutes: 60
runs-on: ubuntu-latest

Expand All @@ -38,21 +40,6 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Update version
run: |
git config --global user.email "tech@composio.dev"
git config --global user.name "Composio"
npm version ${{ github.event.inputs.version }} --no-git-tag-version
- name: Commit and push
run: |
if git diff --quiet; then
echo "No changes to commit"
else
git commit -am "Release ${{ github.event.inputs.version }}" && git push
fi
- name: pnpm build
run: pnpm build

Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composio-core",
"version": "0.3.2",
"version": "0.4.1-beta",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion js/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ACTIONS = {
// actions list end here
};

const COMPOSIO_VERSION = `0.3.0`;
const COMPOSIO_VERSION = `0.4.1-beta`;

module.exports = {
APPS,
Expand Down
2 changes: 1 addition & 1 deletion js/src/frameworks/langchain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("Apps class tests", () => {
repo: "achievementsof.life",
},
entityId: "default",
connectedAccountId: "db3c8d95-73e9-474e-8ae8-edfbdaab98b1",
connectedAccountId: "9442cab3-d54f-4903-976c-ee67ef506c9b",
});

expect(actionOuput).toHaveProperty("successfull", true);
Expand Down
2 changes: 1 addition & 1 deletion js/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Composio {
}

logger.info(
`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}, Log level: ${loggingLevel.toUpperCase()}`
`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`
);

// Initialize the BackendClient with the parsed API key and base URL.
Expand Down
19 changes: 10 additions & 9 deletions js/src/sdk/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { client as axiosClient } from "../client/services.gen";
import apiClient from "../client/client";
import { AxiosInstance } from "axios";
import logger from "../../utils/logger";

import { v4 as uuidv4 } from "uuid";
declare module "axios" {
export interface InternalAxiosRequestConfig {
metadata?: {
Expand All @@ -37,9 +37,14 @@ export const getUserDataJson = () => {
export const setAxiosClientConfig = (axiosClientInstance: AxiosInstance) => {
axiosClientInstance.interceptors.request.use((request) => {
const body = request.data ? JSON.stringify(request.data) : "";
logger.debug(`API Req [${request.method?.toUpperCase()}] ${request.url}`, {
...(body && { body }),
});
// set x-request-id header
request.headers["x-request-id"] = uuidv4();
logger.debug(
`API Req [${request.method?.toUpperCase()}] ${request.url}, x-request-id: ${request.headers["x-request-id"]}`,
{
...(body && { body }),
}
);
request.metadata = { startTime: Date.now() };
return request;
});
Expand All @@ -52,7 +57,6 @@ export const setAxiosClientConfig = (axiosClientInstance: AxiosInstance) => {
);
const requestStartTime = response.config.metadata?.startTime;
const responseTime = requestStartTime ? Date.now() - requestStartTime : 0;
const responseData = response.data ? JSON.stringify(response.data) : "";
const status = response.status;

// @ts-expect-error
Expand All @@ -61,10 +65,7 @@ export const setAxiosClientConfig = (axiosClientInstance: AxiosInstance) => {
responseSize,
};
logger.debug(
`API Res [${method}] ${response.config.url} - ${status} - ${responseSize} KB ${responseTime}ms`,
{
...(responseData && { response: JSON.parse(responseData) }),
}
`API Res [${method}] ${response.config.url} - ${status} - ${responseSize} KB ${responseTime}ms`
);
return response;
},
Expand Down
9 changes: 5 additions & 4 deletions js/src/sdk/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class CEG {
throw new ComposioError(
SDK_ERROR_CODES.COMMON.REQUEST_TIMEOUT,
`ECONNABORTED for ${fullUrl}`,
`Request to ${fullUrl} timed out after the configured timeout period. This could be due to slow network conditions, server performance issues, or the request being too large. Error code: ECONNABORTED`,
`Request to ${fullUrl} timed out after the configured timeout period. This could be due to slow network conditions, server performance issues, or the request being too large. Error code: ETIMEDOUT`,
"Try:\n1. Checking your network speed and stability\n2. Increasing the request timeout setting if needed\n3. Breaking up large requests into smaller chunks\n4. Retrying the request when network conditions improve\n5. Contact tech@composio.dev if the issue persists",
metadata,
error
Expand All @@ -107,9 +107,10 @@ export class CEG {
}

throw new ComposioError(
SDK_ERROR_CODES.COMMON.UNKNOWN,
error.message,
"",
SDK_ERROR_CODES.BACKEND.SERVER_UNREACHABLE,
error.message ||
"Server is unreachable. Please contact tech@composio.dev with the error details.",
"Server is unreachable. Please contact tech@composio.dev with the error details.",
"Please contact tech@composio.dev with the error details.",
metadata,
error
Expand Down
12 changes: 12 additions & 0 deletions js/src/sdk/utils/errors/src/composioError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ export class ComposioError extends Error {
}
}

console.log(
`🚀 [Info] Give Feedback / Get Help: https://dub.composio.dev/discord `
);
console.log(
`🐛 [Info] Create a new issue: https://github.com/ComposioHQ/composio/issues `
);
if (getLogLevel() !== "debug") {
console.log(
`⛔ [Info] If you need to debug this error, set env variable COMPOSIO_LOGGING_LEVEL=debug`
);
}

logError({
error_id: this.errorId,
error_code: this.errCode,
Expand Down
1 change: 1 addition & 0 deletions js/src/sdk/utils/errors/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const SDK_ERROR_CODES = {
UNAUTHORIZED: "BACKEND::UNAUTHORIZED",
SERVER_ERROR: "BACKEND::SERVER_ERROR",
SERVER_UNAVAILABLE: "BACKEND::SERVER_UNAVAILABLE",
SERVER_UNREACHABLE: "BACKEND::SERVER_UNREACHABLE",
UNKNOWN: "BACKEND::UNKNOWN",
},
COMMON: {
Expand Down
28 changes: 19 additions & 9 deletions js/src/sdk/utils/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ import { BatchProcessor } from "../base/batchProcessor";
import { getEnvVariable } from "../../../utils/shared";

export class TELEMETRY_LOGGER {
private static batchProcessor = new BatchProcessor(
1000,
100,
async (data) => {
await TELEMETRY_LOGGER.sendTelemetry(data as Record<string, unknown>[]);
}
);
private static batchProcessor = new BatchProcessor(100, 10, async (data) => {
await TELEMETRY_LOGGER.sendTelemetry(data as Record<string, unknown>[]);
});

private static createTelemetryWrapper(method: Function, className: string) {
return async (...args: unknown[]) => {
const payload = {
eventName: method.name,
data: { className, args },
sdk_meta: ComposioSDKContext,
sdk_meta: {
apiKey: ComposioSDKContext.apiKey,
baseURL: ComposioSDKContext.baseURL,
composioVersion: ComposioSDKContext.composioVersion,
frameworkRuntime: ComposioSDKContext.frameworkRuntime,
source: ComposioSDKContext.source,
isBrowser: typeof window !== "undefined",
},
};

TELEMETRY_LOGGER.batchProcessor.pushItem(payload);
Expand Down Expand Up @@ -61,7 +64,14 @@ export class TELEMETRY_LOGGER {
const payload = {
eventName,
data,
sdk_meta: ComposioSDKContext,
sdk_meta: {
apiKey: ComposioSDKContext.apiKey,
baseURL: ComposioSDKContext.baseURL,
composioVersion: ComposioSDKContext.composioVersion,
frameworkRuntime: ComposioSDKContext.frameworkRuntime,
source: ComposioSDKContext.source,
isBrowser: typeof window !== "undefined",
},
};
TELEMETRY_LOGGER.batchProcessor.pushItem(payload);
}
Expand Down

0 comments on commit d7b9502

Please sign in to comment.