Skip to content

Commit 22f5352

Browse files
authored
Update AxiosPlugin for v1.0+ (#102)
* improved ignore path regex * fix issue #9165 express router entry duplicated * AWS DynamoDB, Lambda, SQS and SNS plugins * component IDs * update AxiosPlugin for v1.0+
1 parent 752f906 commit 22f5352

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/plugins/AxiosPlugin.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,39 @@ import { SpanLayer } from '../proto/language-agent/Tracing_pb';
2626
import DummySpan from '../trace/span/DummySpan';
2727
import { ignoreHttpMethodCheck } from '../config/AgentConfig';
2828
import PluginInstaller from '../core/PluginInstaller';
29+
import * as fs from 'fs';
30+
import * as path from 'path';
2931

3032
class AxiosPlugin implements SwPlugin {
3133
readonly module = 'axios';
3234
readonly versions = '*';
3335

36+
getVersion(installer: PluginInstaller): string {
37+
// TODO: this method will not work in a bundle
38+
try {
39+
const indexPath = installer.resolve(this.module);
40+
const dirname = indexPath.slice(
41+
0,
42+
indexPath.lastIndexOf(`${path.sep}node_modules${path.sep}axios${path.sep}`) + 20,
43+
);
44+
const packageJsonStr = fs.readFileSync(`${dirname}package.json`, { encoding: 'utf-8' });
45+
const pkg = JSON.parse(packageJsonStr);
46+
return pkg.version;
47+
} catch {
48+
return '';
49+
}
50+
}
51+
3452
install(installer: PluginInstaller): void {
3553
this.interceptClientRequest(installer);
3654
}
3755

3856
private interceptClientRequest(installer: PluginInstaller): void {
39-
const Axios = installer.require?.('axios/lib/core/Axios') ?? require('axios/lib/core/Axios');
57+
const axios = installer.require?.('axios') ?? require('axios');
58+
const Axios = axios.Axios;
4059
const _request = Axios.prototype.request;
4160

42-
Axios.prototype.request = function (url?: any, config?: any) {
61+
Axios.prototype.request = axios.request = function (url?: any, config?: any) {
4362
if (typeof url === 'string') config = config ? { ...config, url } : { url };
4463
else config = url ? { ...url } : {};
4564

src/plugins/MySQL2Plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class MySQL2Plugin implements SwPlugin {
3535
// TODO: this method will not work in a bundle
3636
try {
3737
let indexPath = installer.resolve(this.module);
38-
let packageSJonStr = fs.readFileSync(`${path.dirname(indexPath)}${path.sep}package.json`, { encoding: 'utf-8' });
39-
const pkg = JSON.parse(packageSJonStr);
38+
let packageJsonStr = fs.readFileSync(`${path.dirname(indexPath)}${path.sep}package.json`, { encoding: 'utf-8' });
39+
const pkg = JSON.parse(packageJsonStr);
4040
return pkg.version;
4141
} catch {
4242
return '';

0 commit comments

Comments
 (0)