@apm-js-collab/code-transformer 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -7
- package/package.json +2 -2
- package/pkg/orchestrion_js.d.ts +10 -10
- package/pkg/orchestrion_js.js +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
# `@apm-js-collab/code-transformer`
|
|
2
|
-
|
|
3
|
-
This is a fork of
|
|
4
|
-
[`DataDog/orchestrion-js`](https://github.com/DataDog/orchestrion-js/).
|
|
1
|
+
# Orchestrion-JS / `@apm-js-collab/code-transformer`
|
|
5
2
|
|
|
6
3
|
This is a library to aid in instrumenting Node.js libraries at build or load
|
|
7
4
|
time.
|
|
@@ -79,6 +76,32 @@ matcher.free();
|
|
|
79
76
|
transformer.free();
|
|
80
77
|
```
|
|
81
78
|
|
|
79
|
+
### Export Aliases
|
|
80
|
+
|
|
81
|
+
When a module re-exports a function or class under a different name using
|
|
82
|
+
`export { local as exported }`, you can target the **exported** name in your
|
|
83
|
+
`FunctionQuery` by setting `isExportAlias: true`. The transformer will resolve
|
|
84
|
+
the alias to the local declaration before matching.
|
|
85
|
+
|
|
86
|
+
For example, given:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
function f(url) { return fetch(url); }
|
|
90
|
+
export { f as fetchAliased };
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
You can target `fetchAliased` in your config:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const instrumentation = {
|
|
97
|
+
channelName: "my-channel",
|
|
98
|
+
module: { name: "my-module", versionRange: ">=1.0.0", filePath: "./index.mjs" },
|
|
99
|
+
functionQuery: { functionName: "fetchAliased", kind: "Async", isExportAlias: true },
|
|
100
|
+
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This also works for class exports (e.g., `export { MyClass as PublicClass }`).
|
|
104
|
+
|
|
82
105
|
### API Reference
|
|
83
106
|
|
|
84
107
|
```ts
|
|
@@ -91,20 +114,23 @@ type FunctionKind = "Sync" | "Async";
|
|
|
91
114
|
```ts
|
|
92
115
|
type FunctionQuery =
|
|
93
116
|
| // Match class constructor
|
|
94
|
-
{ className: string; index?: number }
|
|
117
|
+
{ className: string; index?: number; isExportAlias?: boolean }
|
|
95
118
|
| // Match class method
|
|
96
119
|
{
|
|
97
120
|
className: string;
|
|
98
121
|
methodName: string;
|
|
99
122
|
kind: FunctionKind;
|
|
100
123
|
index?: number;
|
|
124
|
+
isExportAlias?: boolean;
|
|
101
125
|
}
|
|
102
126
|
| // Match method on objects
|
|
103
127
|
{ methodName: string; kind: FunctionKind; index?: number }
|
|
104
128
|
| // Match standalone function
|
|
105
|
-
{ functionName: string; kind: FunctionKind; index?: number }
|
|
129
|
+
{ functionName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean }
|
|
106
130
|
| // Match arrow function or function expression
|
|
107
|
-
{ expressionName: string; kind: FunctionKind; index?: number };
|
|
131
|
+
{ expressionName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean };
|
|
132
|
+
| // Match private class methods
|
|
133
|
+
{ className: string; privateMethodName: string; kind: FunctionKind; index?: number };
|
|
108
134
|
```
|
|
109
135
|
|
|
110
136
|
#### **`ModuleMatcher`**
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apm-js-collab/code-transformer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/
|
|
7
|
+
"url": "https://github.com/nodejs/orchestrion-js.git"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"./pkg/orchestrion_js.js",
|
package/pkg/orchestrion_js.d.ts
CHANGED
|
@@ -18,6 +18,16 @@ export interface TransformOutput {
|
|
|
18
18
|
map: string | undefined;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Describes which function to instrument
|
|
23
|
+
*/
|
|
24
|
+
export type FunctionQuery = { className: string; methodName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean } | { className: string; privateMethodName: string; kind: FunctionKind; index?: number } | { className: string; index?: number; isExportAlias?: boolean } | { methodName: string; kind: FunctionKind; index?: number } | { functionName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean } | { expressionName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The kind of function - Sync or returns a promise
|
|
28
|
+
*/
|
|
29
|
+
export type FunctionKind = "Sync" | "Async";
|
|
30
|
+
|
|
21
31
|
/**
|
|
22
32
|
* Configuration for injecting instrumentation code
|
|
23
33
|
*/
|
|
@@ -54,16 +64,6 @@ export interface ModuleMatcher {
|
|
|
54
64
|
filePath: string;
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
/**
|
|
58
|
-
* Describes which function to instrument
|
|
59
|
-
*/
|
|
60
|
-
export type FunctionQuery = { className: string; methodName: string; kind: FunctionKind; index?: number } | { className: string; index?: number } | { methodName: string; kind: FunctionKind; index?: number } | { functionName: string; kind: FunctionKind; index?: number } | { expressionName: string; kind: FunctionKind; index?: number };
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The kind of function - Sync or returns a promise
|
|
64
|
-
*/
|
|
65
|
-
export type FunctionKind = "Sync" | "Async";
|
|
66
|
-
|
|
67
67
|
/**
|
|
68
68
|
* The type of module being passed - ESM, CJS or unknown
|
|
69
69
|
*/
|