Skip to content

Commit

Permalink
towards monitorAxios option
Browse files Browse the repository at this point in the history
  • Loading branch information
dawkaka committed Jun 7, 2024
1 parent 12faec4 commit a3318aa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 40 deletions.
5 changes: 3 additions & 2 deletions lib/apitoolkit.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PubSub } from '@google-cloud/pubsub';
import { ReportError } from 'apitoolkit-js';
import { AxiosInstance } from 'axios';
import { AxiosInstance, AxiosStatic } from 'axios';
import { NextFunction, Request, Response } from 'express';
export type ATError = {
when: string;
Expand Down Expand Up @@ -45,6 +45,7 @@ export type Config = {
clientMetadata?: ClientMetadata;
serviceVersion?: string;
tags?: string[];
moitorAxios?: AxiosInstance;
};
type ClientMetadata = {
project_id: string;
Expand All @@ -63,7 +64,7 @@ export declare class APIToolkit {
project_id: string;
config: Config;
};
observeAxios(axiosInstance: AxiosInstance, urlWildcard?: string | undefined, redactHeaders?: string[] | undefined, redactRequestBody?: string[] | undefined, redactResponseBody?: string[] | undefined): import("axios").AxiosInstance;
observeAxios(axiosInstance: AxiosStatic, urlWildcard?: string | undefined, redactHeaders?: string[] | undefined, redactRequestBody?: string[] | undefined, redactResponseBody?: string[] | undefined): AxiosInstance;
ReportError: typeof ReportError;
expressMiddleware(req: Request, res: Response, next: NextFunction): void;
errorHandler(err: any, req: Request, res: Response, next: NextFunction): void;
Expand Down
3 changes: 3 additions & 0 deletions lib/apitoolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class APIToolkit {
}
}
};
if (config.moitorAxios) {
(0, apitoolkit_js_1.observeAxiosGlobal)(config.moitorAxios);
}
this.expressMiddleware = this.expressMiddleware.bind(this);
}
static NewClient(config) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apitoolkit-express",
"version": "2.2.5",
"version": "2.2.6",
"description": "Nodejs SDK for the API Toolkit Monitoring and Reliability platform written in Typescript",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -41,8 +41,8 @@
"@types/supertest": "^2.0.15",
"@types/sync-fetch": "^0.4.2",
"@types/uuid": "^9.0.6",
"apitoolkit-js": "^3.3.0",
"axios": "^1.6.0",
"apitoolkit-js": "^3.3.1",
"axios": "^1.7.0",
"busboy": "^1.6.0",
"express": "^4.18.2",
"formidable": "^3.5.1",
Expand Down
44 changes: 11 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/apitoolkit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PubSub, Topic } from '@google-cloud/pubsub';
import { asyncLocalStorage, buildPayload, observeAxios, ReportError } from 'apitoolkit-js';
import axios, { AxiosStatic, AxiosInstance } from 'axios';
import { asyncLocalStorage, buildPayload, observeAxios, observeAxiosGlobal, ReportError } from 'apitoolkit-js';

Check failure on line 2 in src/apitoolkit.ts

View workflow job for this annotation

GitHub Actions / build

'"apitoolkit-js"' has no exported member named 'observeAxiosGlobal'. Did you mean 'observeAxios'?
import { AxiosInstance, AxiosStatic } from 'axios';
import { NextFunction, Request, Response } from 'express';
import fetch from 'sync-fetch';
import { v4 as uuidv4 } from 'uuid';
Expand Down Expand Up @@ -49,6 +49,7 @@ export type Config = {
clientMetadata?: ClientMetadata;
serviceVersion?: string;
tags?: string[];
moitorAxios?: AxiosInstance;
};

type ClientMetadata = {
Expand Down Expand Up @@ -93,6 +94,9 @@ export class APIToolkit {
}
}
};
if (config.moitorAxios) {
observeAxiosGlobal(config.moitorAxios as any);
}
this.expressMiddleware = this.expressMiddleware.bind(this);
}

Expand Down

0 comments on commit a3318aa

Please sign in to comment.