opentelemetry-esbuild-plugin-node 2.0.0 → 3.0.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 +10 -5
- package/build/src/config/index.d.ts +1 -1
- package/build/src/config/index.js +2 -2
- package/build/src/config/index.js.map +1 -1
- package/build/src/config/main.d.ts +11 -16
- package/build/src/config/main.js +10 -12
- package/build/src/config/main.js.map +1 -1
- package/build/src/plugin.js +33 -6
- package/build/src/plugin.js.map +1 -1
- package/build/src/types.d.ts +44 -0
- package/build/src/types.js.map +1 -1
- package/package.json +15 -13
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Compatible with OpenTelemetry JS API and SDK `1.0+`.
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
npm
|
|
19
|
+
npm i -D opentelemetry-esbuild-plugin-node
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Usage: Esbuild plugin
|
|
@@ -46,11 +46,14 @@ build({
|
|
|
46
46
|
|
|
47
47
|
This packages for Node automatically loads instrumentations for Node builtin modules and common packages.
|
|
48
48
|
|
|
49
|
-
Enable
|
|
49
|
+
Enable instrumentation by configuring it in your esbuild script:
|
|
50
50
|
|
|
51
51
|
```javascript
|
|
52
52
|
const { openTelemetryPlugin } = require('opentelemetry-esbuild-plugin-node');
|
|
53
53
|
const { build } = require('esbuild');
|
|
54
|
+
const {
|
|
55
|
+
getNodeAutoInstrumentations,
|
|
56
|
+
} = require('@opentelemetry/auto-instrumentations-node');
|
|
54
57
|
|
|
55
58
|
build({
|
|
56
59
|
entryPoints: ['src/server.ts'],
|
|
@@ -59,11 +62,13 @@ build({
|
|
|
59
62
|
target: 'node20',
|
|
60
63
|
platform: 'node',
|
|
61
64
|
sourcemap: true,
|
|
62
|
-
plugins: [
|
|
65
|
+
plugins: [
|
|
66
|
+
openTelemetryPlugin({ instrumentations: getNodeAutoInstrumentations() }),
|
|
67
|
+
],
|
|
63
68
|
});
|
|
64
69
|
```
|
|
65
70
|
|
|
66
|
-
Custom configuration for each of the instrumentations can be passed to the plugin, by providing an object with the name of the instrumentation as a key, and its configuration as the value.
|
|
71
|
+
Custom configuration for each of the instrumentations can be passed to the plugin, by providing an object with the name of the instrumentation as a key, and its configuration as the value. Though passing instrumentations in directly is preferred, and the ability to configure via `instrumentationConfig` rather than passing in instrumentations directly will be removed in a future version.
|
|
67
72
|
|
|
68
73
|
```javascript
|
|
69
74
|
const { openTelemetryPlugin } = require('opentelemetry-esbuild-plugin-node');
|
|
@@ -96,7 +101,7 @@ for builtins or add any additional instrumentations.
|
|
|
96
101
|
|
|
97
102
|
### Gotchas
|
|
98
103
|
|
|
99
|
-
There are limitations to the configuration options for each package. Most notably, any functions
|
|
104
|
+
There are limitations to the configuration options for each package. Most notably, any functions are not allowed to be passed in to plugins.
|
|
100
105
|
|
|
101
106
|
The reason for this is that the current mechanism of instrumenting packages involves stringifying the instrumentation configs, which does not account for any external scoped dependencies, and thus creates subtle opportunities for bugs.
|
|
102
107
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getOtelPackageToInstrumentationConfig } from './main';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.getOtelPackageToInstrumentationConfig = void 0;
|
|
19
19
|
var main_1 = require("./main");
|
|
20
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "getOtelPackageToInstrumentationConfig", { enumerable: true, get: function () { return main_1.getOtelPackageToInstrumentationConfig; } });
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+BAA+D;AAAtD,6HAAA,qCAAqC,OAAA","sourcesContent":["/*\n * Copyright The Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { getOtelPackageToInstrumentationConfig } from './main';\n"]}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
|
|
1
|
+
import { Instrumentation, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
2
|
import { EsbuildInstrumentationConfigMap } from '../types';
|
|
3
|
-
export declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
oTelInstrumentationClass: string;
|
|
14
|
-
configGenerator: <T extends {
|
|
15
|
-
enabled?: boolean;
|
|
16
|
-
}>(config?: T) => string | undefined;
|
|
17
|
-
}>;
|
|
3
|
+
export declare function getOtelPackageToInstrumentationConfig(instrumentations: Instrumentation[]): {
|
|
4
|
+
otelPackageToInstrumentationConfig: Record<string, {
|
|
5
|
+
oTelInstrumentationPackage: keyof EsbuildInstrumentationConfigMap;
|
|
6
|
+
oTelInstrumentationClass: string;
|
|
7
|
+
configGenerator: <T extends {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
}>(config?: T) => string | undefined;
|
|
10
|
+
}>;
|
|
11
|
+
instrumentationModuleDefinitions: InstrumentationModuleDefinition[];
|
|
12
|
+
};
|
|
18
13
|
//# sourceMappingURL=main.d.ts.map
|
package/build/src/config/main.js
CHANGED
|
@@ -15,13 +15,8 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.otelPackageToInstrumentationConfig = exports.instrumentationModuleDefinitions = void 0;
|
|
19
18
|
exports.getOtelPackageToInstrumentationConfig = getOtelPackageToInstrumentationConfig;
|
|
20
19
|
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
21
|
-
const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
|
|
22
|
-
const instrumentations = (0, auto_instrumentations_node_1.getNodeAutoInstrumentations)();
|
|
23
|
-
const instrumentationModuleDefinitionsByInstrumentationName = Object.fromEntries(instrumentations.map(i => [i.instrumentationName, getModuleDefinitions(i)]));
|
|
24
|
-
exports.instrumentationModuleDefinitions = Object.values(instrumentationModuleDefinitionsByInstrumentationName).flat();
|
|
25
20
|
function getModuleDefinitions(instrumentation) {
|
|
26
21
|
var _a;
|
|
27
22
|
if (instrumentation instanceof instrumentation_1.InstrumentationBase) {
|
|
@@ -34,15 +29,16 @@ function configGenerator(config) {
|
|
|
34
29
|
return;
|
|
35
30
|
return JSON.stringify(Object.fromEntries(Object.entries(config).filter(([, v]) => typeof v !== 'function')));
|
|
36
31
|
}
|
|
37
|
-
function getOtelPackageToInstrumentationConfig() {
|
|
32
|
+
function getOtelPackageToInstrumentationConfig(instrumentations) {
|
|
33
|
+
const instrumentationModuleDefinitionsByInstrumentationName = Object.fromEntries(instrumentations.map(i => [
|
|
34
|
+
i.instrumentationName,
|
|
35
|
+
getModuleDefinitions(i),
|
|
36
|
+
]));
|
|
37
|
+
const instrumentationModuleDefinitions = Object.values(instrumentationModuleDefinitionsByInstrumentationName).flat();
|
|
38
38
|
const otelPackageToInstrumentationConfig = {};
|
|
39
39
|
for (const instrumentation of instrumentations) {
|
|
40
40
|
const moduleDefinitions = instrumentationModuleDefinitionsByInstrumentationName[instrumentation.instrumentationName];
|
|
41
41
|
for (const instrumentationModuleDefinition of moduleDefinitions) {
|
|
42
|
-
// For some reason @opentelemetry/instrumentation-generic-pool reports its name as just Instrumentation
|
|
43
|
-
// TODO: See if this goes away with an upgrade
|
|
44
|
-
if (instrumentation.constructor.name === 'Instrumentation')
|
|
45
|
-
continue;
|
|
46
42
|
otelPackageToInstrumentationConfig[instrumentationModuleDefinition.name] =
|
|
47
43
|
{
|
|
48
44
|
oTelInstrumentationPackage: instrumentation.instrumentationName,
|
|
@@ -51,7 +47,9 @@ function getOtelPackageToInstrumentationConfig() {
|
|
|
51
47
|
};
|
|
52
48
|
}
|
|
53
49
|
}
|
|
54
|
-
return
|
|
50
|
+
return {
|
|
51
|
+
otelPackageToInstrumentationConfig,
|
|
52
|
+
instrumentationModuleDefinitions,
|
|
53
|
+
};
|
|
55
54
|
}
|
|
56
|
-
exports.otelPackageToInstrumentationConfig = getOtelPackageToInstrumentationConfig();
|
|
57
55
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/config/main.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/config/main.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AA+BH,sFA6CC;AA1ED,oEAIwC;AAIxC,SAAS,oBAAoB,CAC3B,eAAgC;;IAEhC,IAAI,eAAe,YAAY,qCAAmB,EAAE,CAAC;QACnD,OAAO,MAAA,eAAe,CAAC,oBAAoB,EAAE,mCAAI,EAAE,CAAC;IACtD,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,eAAe,CACtB,MAAU;IAEV,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,OAAO,IAAI,CAAC,SAAS,CACnB,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAClE,CACF,CAAC;AACJ,CAAC;AAED,SAAgB,qCAAqC,CACnD,gBAAmC;IAEnC,MAAM,qDAAqD,GACzD,MAAM,CAAC,WAAW,CAChB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACxB,CAAC,CAAC,mBAAmB;QACrB,oBAAoB,CAAC,CAAC,CAAC;KACxB,CAAC,CACH,CAAC;IAEJ,MAAM,gCAAgC,GAAG,MAAM,CAAC,MAAM,CACpD,qDAAqD,CACtD,CAAC,IAAI,EAAE,CAAC;IAET,MAAM,kCAAkC,GASpC,EAAE,CAAC;IACP,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE,CAAC;QAC/C,MAAM,iBAAiB,GACrB,qDAAqD,CACnD,eAAe,CAAC,mBAAmB,CACpC,CAAC;QAEJ,KAAK,MAAM,+BAA+B,IAAI,iBAAiB,EAAE,CAAC;YAChE,kCAAkC,CAAC,+BAA+B,CAAC,IAAI,CAAC;gBACtE;oBACE,0BAA0B,EACxB,eAAe,CAAC,mBAA4D;oBAC9E,wBAAwB,EAAE,eAAe,CAAC,WAAW,CAAC,IAAI;oBAC1D,eAAe;iBAChB,CAAC;QACN,CAAC;IACH,CAAC;IACD,OAAO;QACL,kCAAkC;QAClC,gCAAgC;KACjC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Instrumentation,\n InstrumentationBase,\n InstrumentationModuleDefinition,\n} from '@opentelemetry/instrumentation';\n\nimport { EsbuildInstrumentationConfigMap } from '../types';\n\nfunction getModuleDefinitions(\n instrumentation: Instrumentation\n): InstrumentationModuleDefinition[] {\n if (instrumentation instanceof InstrumentationBase) {\n return instrumentation.getModuleDefinitions() ?? [];\n }\n\n return [];\n}\n\nfunction configGenerator<T extends { enabled?: boolean }>(\n config?: T\n): string | undefined {\n if (!config) return;\n return JSON.stringify(\n Object.fromEntries(\n Object.entries(config).filter(([, v]) => typeof v !== 'function')\n )\n );\n}\n\nexport function getOtelPackageToInstrumentationConfig(\n instrumentations: Instrumentation[]\n) {\n const instrumentationModuleDefinitionsByInstrumentationName =\n Object.fromEntries(\n instrumentations.map(i => [\n i.instrumentationName,\n getModuleDefinitions(i),\n ])\n );\n\n const instrumentationModuleDefinitions = Object.values(\n instrumentationModuleDefinitionsByInstrumentationName\n ).flat();\n\n const otelPackageToInstrumentationConfig: Record<\n string,\n {\n oTelInstrumentationPackage: keyof EsbuildInstrumentationConfigMap;\n oTelInstrumentationClass: string;\n configGenerator: <T extends { enabled?: boolean }>(\n config?: T\n ) => string | undefined;\n }\n > = {};\n for (const instrumentation of instrumentations) {\n const moduleDefinitions =\n instrumentationModuleDefinitionsByInstrumentationName[\n instrumentation.instrumentationName\n ];\n\n for (const instrumentationModuleDefinition of moduleDefinitions) {\n otelPackageToInstrumentationConfig[instrumentationModuleDefinition.name] =\n {\n oTelInstrumentationPackage:\n instrumentation.instrumentationName as keyof EsbuildInstrumentationConfigMap,\n oTelInstrumentationClass: instrumentation.constructor.name,\n configGenerator,\n };\n }\n }\n return {\n otelPackageToInstrumentationConfig,\n instrumentationModuleDefinitions,\n };\n}\n"]}
|
package/build/src/plugin.js
CHANGED
|
@@ -17,14 +17,25 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.openTelemetryPlugin = openTelemetryPlugin;
|
|
19
19
|
const path_1 = require("path");
|
|
20
|
-
const main_1 = require("./config/main");
|
|
21
20
|
const module_1 = require("module");
|
|
22
21
|
const promises_1 = require("fs/promises");
|
|
23
22
|
const semver_1 = require("semver");
|
|
24
23
|
const common_1 = require("./common");
|
|
24
|
+
const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
|
|
25
|
+
const config_1 = require("./config");
|
|
25
26
|
const NODE_MODULES = 'node_modules/';
|
|
26
27
|
const BUILT_INS = new Set(module_1.builtinModules.flatMap(b => [b, `node:${b}`]));
|
|
28
|
+
function validateConfig(pluginConfig) {
|
|
29
|
+
if (!pluginConfig)
|
|
30
|
+
return;
|
|
31
|
+
if (pluginConfig.instrumentationConfig && pluginConfig.instrumentations) {
|
|
32
|
+
throw new Error('OpenTelemetryPluginParams and instrumentations must not be used together');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
27
35
|
function openTelemetryPlugin(pluginConfig) {
|
|
36
|
+
var _a;
|
|
37
|
+
validateConfig(pluginConfig);
|
|
38
|
+
const { otelPackageToInstrumentationConfig, instrumentationModuleDefinitions, } = (0, config_1.getOtelPackageToInstrumentationConfig)((_a = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.instrumentations) !== null && _a !== void 0 ? _a : (0, auto_instrumentations_node_1.getNodeAutoInstrumentations)());
|
|
28
39
|
return {
|
|
29
40
|
name: 'open-telemetry',
|
|
30
41
|
setup(build) {
|
|
@@ -64,6 +75,7 @@ function openTelemetryPlugin(pluginConfig) {
|
|
|
64
75
|
return;
|
|
65
76
|
// See if we have an instrumentation registered for this package
|
|
66
77
|
const matchingInstrumentation = getInstrumentation({
|
|
78
|
+
instrumentationModuleDefinitions,
|
|
67
79
|
extractedModule,
|
|
68
80
|
moduleVersion,
|
|
69
81
|
path: args.path,
|
|
@@ -79,15 +91,17 @@ function openTelemetryPlugin(pluginConfig) {
|
|
|
79
91
|
return { path, pluginData };
|
|
80
92
|
});
|
|
81
93
|
build.onLoad({ filter: /.*/ }, async ({ path, pluginData }) => {
|
|
82
|
-
var _a;
|
|
83
94
|
// Ignore any packages that don't have an instrumentation registered for them
|
|
84
95
|
if (!(pluginData === null || pluginData === void 0 ? void 0 : pluginData.shouldPatchPackage))
|
|
85
96
|
return;
|
|
86
97
|
const contents = await (0, promises_1.readFile)(path);
|
|
87
|
-
const config =
|
|
98
|
+
const config = otelPackageToInstrumentationConfig[pluginData.instrumentationName];
|
|
88
99
|
if (!config)
|
|
89
100
|
return;
|
|
90
|
-
const packageConfig = (
|
|
101
|
+
const packageConfig = getPackageConfig({
|
|
102
|
+
pluginConfig,
|
|
103
|
+
oTelInstrumentationPackage: config.oTelInstrumentationPackage,
|
|
104
|
+
});
|
|
91
105
|
const extractedModule = pluginData.extractedModule;
|
|
92
106
|
return {
|
|
93
107
|
contents: (0, common_1.wrapModule)(contents.toString(), {
|
|
@@ -104,6 +118,19 @@ function openTelemetryPlugin(pluginConfig) {
|
|
|
104
118
|
},
|
|
105
119
|
};
|
|
106
120
|
}
|
|
121
|
+
function getPackageConfig({ pluginConfig, oTelInstrumentationPackage, }) {
|
|
122
|
+
var _a;
|
|
123
|
+
if (!pluginConfig)
|
|
124
|
+
return;
|
|
125
|
+
if (pluginConfig.instrumentations) {
|
|
126
|
+
const matchingPlugin = pluginConfig.instrumentations.find(i => i.instrumentationName === oTelInstrumentationPackage);
|
|
127
|
+
if (!matchingPlugin) {
|
|
128
|
+
throw new Error(`Instrumentation ${oTelInstrumentationPackage} was found but does not exist in list of instrumentations`);
|
|
129
|
+
}
|
|
130
|
+
return matchingPlugin.getConfig();
|
|
131
|
+
}
|
|
132
|
+
return (_a = pluginConfig.instrumentationConfig) === null || _a === void 0 ? void 0 : _a[oTelInstrumentationPackage];
|
|
133
|
+
}
|
|
107
134
|
/**
|
|
108
135
|
* For a given full path to a module,
|
|
109
136
|
* return the package name it belongs to and the local path to the module
|
|
@@ -173,8 +200,8 @@ async function getModuleVersion({ extractedModule, resolveDir, build, }) {
|
|
|
173
200
|
moduleVersionByPackageJsonPath.set(path, moduleVersion);
|
|
174
201
|
return moduleVersion;
|
|
175
202
|
}
|
|
176
|
-
function getInstrumentation({ extractedModule, path, moduleVersion, }) {
|
|
177
|
-
for (const instrumentationModuleDefinition of
|
|
203
|
+
function getInstrumentation({ instrumentationModuleDefinitions, extractedModule, path, moduleVersion, }) {
|
|
204
|
+
for (const instrumentationModuleDefinition of instrumentationModuleDefinitions) {
|
|
178
205
|
const fullModulePath = `${extractedModule.package}/${extractedModule.path}`;
|
|
179
206
|
const nameMatches = instrumentationModuleDefinition.name === path ||
|
|
180
207
|
instrumentationModuleDefinition.name === fullModulePath;
|
package/build/src/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAyBH,kDAsGC;AAtHD,+BAAqC;AACrC,wCAGuB;AAGvB,mCAAwC;AACxC,0CAAuC;AACvC,mCAAmC;AACnC,qCAAsC;AAEtC,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,uBAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEzE,SAAgB,mBAAmB,CACjC,YAAwC;IAExC,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,KAAK,CAAC,KAAK;YACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;gBAC7C,IACE,kBAAkB,CAAC;oBACjB,SAAS,EAAE,IAAI,CAAC,SAAS;oBACzB,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,eAA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IAAI,CAAC,gBAAgB,CAAC,EAAE,CACpD,IAAA,kBAAS,EAAC,aAAa,EAAE,gBAAgB,CAAC,CAC3C,CAAC;QACJ,CAAC,CAAC,EACF,CAAC;YACD,OAAO,+BAA+B,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/*\n * Copyright The Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ExtractedModule,\n OnLoadArgs,\n OpenTelemetryPluginParams,\n PluginData,\n} from './types';\nimport { Plugin, PluginBuild } from 'esbuild';\nimport { dirname, join } from 'path';\nimport {\n instrumentationModuleDefinitions,\n otelPackageToInstrumentationConfig,\n} from './config/main';\n\nimport { InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport { builtinModules } from 'module';\nimport { readFile } from 'fs/promises';\nimport { satisfies } from 'semver';\nimport { wrapModule } from './common';\n\nconst NODE_MODULES = 'node_modules/';\n\nconst BUILT_INS = new Set(builtinModules.flatMap(b => [b, `node:${b}`]));\n\nexport function openTelemetryPlugin(\n pluginConfig?: OpenTelemetryPluginParams\n): Plugin {\n return {\n name: 'open-telemetry',\n setup(build) {\n build.onResolve({ filter: /.*/ }, async args => {\n if (\n shouldIgnoreModule({\n namespace: args.namespace,\n path: args.path,\n importer: args.importer,\n externalModules: pluginConfig?.externalModules,\n pathPrefixesToIgnore: pluginConfig?.pathPrefixesToIgnore,\n })\n ) {\n return;\n }\n\n let path;\n let extractedModule;\n\n try {\n const result = extractPackageAndModulePath(\n args.path,\n args.resolveDir\n );\n path = result.path;\n extractedModule = result.extractedModule;\n } catch {\n // Some libraries like `mongodb` require optional dependencies, which may not be present and their absence doesn't break the code\n // Currently esbuild doesn't provide any better way to handle this in plugins: https://github.com/evanw/esbuild/issues/1127\n }\n\n // If it's a local import, don't patch it\n if (!extractedModule) return;\n\n // We'll rely on the OTel auto-instrumentation at runtime to patch builtin modules\n if (isBuiltIn(args.path, extractedModule)) return;\n\n const moduleVersion = await getModuleVersion({\n extractedModule,\n resolveDir: args.resolveDir,\n build,\n });\n if (!moduleVersion) return;\n\n // See if we have an instrumentation registered for this package\n const matchingInstrumentation = getInstrumentation({\n extractedModule,\n moduleVersion,\n path: args.path,\n });\n if (!matchingInstrumentation) return;\n\n const pluginData: PluginData = {\n extractedModule,\n moduleVersion,\n shouldPatchPackage: true,\n instrumentationName: matchingInstrumentation.name,\n };\n\n return { path, pluginData };\n });\n\n build.onLoad(\n { filter: /.*/ },\n async ({ path, pluginData }: OnLoadArgs) => {\n // Ignore any packages that don't have an instrumentation registered for them\n if (!pluginData?.shouldPatchPackage) return;\n\n const contents = await readFile(path);\n\n const config =\n otelPackageToInstrumentationConfig[pluginData.instrumentationName];\n if (!config) return;\n\n const packageConfig =\n pluginConfig?.instrumentationConfig?.[\n config.oTelInstrumentationPackage\n ];\n const extractedModule = pluginData.extractedModule;\n\n return {\n contents: wrapModule(contents.toString(), {\n path: join(\n extractedModule.package || '',\n extractedModule.path || ''\n ),\n moduleVersion: pluginData.moduleVersion,\n instrumentationName: pluginData.instrumentationName,\n oTelInstrumentationClass: config.oTelInstrumentationClass,\n oTelInstrumentationPackage: config.oTelInstrumentationPackage,\n oTelInstrumentationConstructorArgs:\n config.configGenerator(packageConfig),\n }),\n resolveDir: dirname(path),\n };\n }\n );\n },\n };\n}\n\n/**\n * For a given full path to a module,\n * return the package name it belongs to and the local path to the module\n * input: '/foo/node_modules/@co/stuff/foo/bar/baz.js'\n * output: { package: '@co/stuff', path: 'foo/bar/baz.js' }\n */\nfunction extractPackageAndModulePath(\n originalPath: string,\n resolveDir: string\n): { path: string; extractedModule: ExtractedModule | null } {\n // @see https://github.com/nodejs/node/issues/47000\n const path = require.resolve(\n originalPath === '.' ? './' : originalPath === '..' ? '../' : originalPath,\n { paths: [resolveDir] }\n );\n\n const nodeModulesIndex = path.lastIndexOf(NODE_MODULES);\n if (nodeModulesIndex < 0) return { path, extractedModule: null };\n\n const subPath = path.substring(nodeModulesIndex + NODE_MODULES.length);\n const firstSlashIndex = subPath.indexOf('/');\n\n if (!subPath.startsWith('@')) {\n return {\n path,\n extractedModule: {\n package: subPath.substring(0, firstSlashIndex),\n path: subPath.substring(firstSlashIndex + 1),\n },\n };\n }\n\n const secondSlash = subPath.substring(firstSlashIndex + 1).indexOf('/');\n return {\n path,\n extractedModule: {\n package: subPath.substring(0, firstSlashIndex + secondSlash + 1),\n path: subPath.substring(firstSlashIndex + secondSlash + 2),\n },\n };\n}\n\nfunction shouldIgnoreModule({\n namespace,\n path,\n importer,\n externalModules,\n pathPrefixesToIgnore,\n}: {\n namespace: string;\n path: string;\n importer: string;\n externalModules?: string[];\n pathPrefixesToIgnore?: string[];\n}): boolean {\n // If onLoad is being triggered from another plugin, ignore it\n if (namespace !== 'file') return true;\n // If it's a local import from our code, ignore it\n if (!importer.includes(NODE_MODULES) && path.startsWith('.')) return true;\n // If it starts with a prefix to ignore, ignore it\n if (pathPrefixesToIgnore?.some(prefix => path.startsWith(prefix))) {\n return true;\n }\n // If it's marked as external, ignore it\n if (externalModules?.includes(path)) return true;\n\n return false;\n}\n\nfunction isBuiltIn(path: string, extractedModule: ExtractedModule): boolean {\n return (\n BUILT_INS.has(path) ||\n BUILT_INS.has(`${extractedModule.package}/${extractedModule.path}`)\n );\n}\n\nconst moduleVersionByPackageJsonPath = new Map<string, string>();\n\nasync function getModuleVersion({\n extractedModule,\n resolveDir,\n build,\n}: {\n extractedModule: ExtractedModule;\n resolveDir: string;\n build: PluginBuild;\n}) {\n const path = `${extractedModule.package}/package.json`;\n const contents = moduleVersionByPackageJsonPath.get(path);\n if (contents) return contents;\n\n const { path: packageJsonPath } = await build.resolve(path, {\n resolveDir,\n kind: 'require-resolve',\n });\n if (!packageJsonPath) return;\n\n const packageJsonContents = await readFile(packageJsonPath);\n const moduleVersion = JSON.parse(packageJsonContents.toString()).version;\n moduleVersionByPackageJsonPath.set(path, moduleVersion);\n return moduleVersion;\n}\n\nfunction getInstrumentation({\n extractedModule,\n path,\n moduleVersion,\n}: {\n extractedModule: ExtractedModule;\n path: string;\n moduleVersion: string;\n}): InstrumentationModuleDefinition | null {\n for (const instrumentationModuleDefinition of instrumentationModuleDefinitions) {\n const fullModulePath = `${extractedModule.package}/${extractedModule.path}`;\n const nameMatches =\n instrumentationModuleDefinition.name === path ||\n instrumentationModuleDefinition.name === fullModulePath;\n\n if (!nameMatches) {\n const fileMatch = instrumentationModuleDefinition.files.find(file => {\n return file.name === path || file.name === fullModulePath;\n });\n if (!fileMatch) continue;\n }\n\n if (\n instrumentationModuleDefinition.supportedVersions.some(supportedVersion =>\n satisfies(moduleVersion, supportedVersion)\n )\n ) {\n return instrumentationModuleDefinition;\n }\n\n if (\n instrumentationModuleDefinition.files.some(file => {\n if (file.name !== path && file.name !== fullModulePath) return false;\n return file.supportedVersions.some(supportedVersion =>\n satisfies(moduleVersion, supportedVersion)\n );\n })\n ) {\n return instrumentationModuleDefinition;\n }\n }\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAiCH,kDAgHC;AAvID,+BAAqC;AAGrC,mCAAwC;AACxC,0CAAuC;AACvC,mCAAmC;AACnC,qCAAsC;AACtC,0FAAwF;AACxF,qCAAiE;AAEjE,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,uBAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAA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,CAAC,IAAI,KAAK,cAAc;gBAAE,OAAO,KAAK,CAAC;YACrE,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CACpD,IAAA,kBAAS,EAAC,aAAa,EAAE,gBAAgB,CAAC,CAC3C,CAAC;QACJ,CAAC,CAAC,EACF,CAAC;YACD,OAAO,+BAA+B,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/*\n * Copyright The Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EsbuildInstrumentationConfigMap,\n ExtractedModule,\n OnLoadArgs,\n OpenTelemetryPluginParams,\n PluginData,\n} from './types';\nimport { Plugin, PluginBuild } from 'esbuild';\nimport { dirname, join } from 'path';\n\nimport { InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport { builtinModules } from 'module';\nimport { readFile } from 'fs/promises';\nimport { satisfies } from 'semver';\nimport { wrapModule } from './common';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { getOtelPackageToInstrumentationConfig } from './config';\n\nconst NODE_MODULES = 'node_modules/';\n\nconst BUILT_INS = new Set(builtinModules.flatMap(b => [b, `node:${b}`]));\n\nfunction validateConfig(pluginConfig?: OpenTelemetryPluginParams) {\n if (!pluginConfig) return;\n if (pluginConfig.instrumentationConfig && pluginConfig.instrumentations) {\n throw new Error(\n 'OpenTelemetryPluginParams and instrumentations must not be used together'\n );\n }\n}\n\nexport function openTelemetryPlugin(\n pluginConfig?: OpenTelemetryPluginParams\n): Plugin {\n validateConfig(pluginConfig);\n\n const {\n otelPackageToInstrumentationConfig,\n instrumentationModuleDefinitions,\n } = getOtelPackageToInstrumentationConfig(\n pluginConfig?.instrumentations ?? getNodeAutoInstrumentations()\n );\n\n return {\n name: 'open-telemetry',\n setup(build) {\n build.onResolve({ filter: /.*/ }, async args => {\n if (\n shouldIgnoreModule({\n namespace: args.namespace,\n path: args.path,\n importer: args.importer,\n externalModules: pluginConfig?.externalModules,\n pathPrefixesToIgnore: pluginConfig?.pathPrefixesToIgnore,\n })\n ) {\n return;\n }\n\n let path;\n let extractedModule;\n\n try {\n const result = extractPackageAndModulePath(\n args.path,\n args.resolveDir\n );\n path = result.path;\n extractedModule = result.extractedModule;\n } catch {\n // Some libraries like `mongodb` require optional dependencies, which may not be present and their absence doesn't break the code\n // Currently esbuild doesn't provide any better way to handle this in plugins: https://github.com/evanw/esbuild/issues/1127\n }\n\n // If it's a local import, don't patch it\n if (!extractedModule) return;\n\n // We'll rely on the OTel auto-instrumentation at runtime to patch builtin modules\n if (isBuiltIn(args.path, extractedModule)) return;\n\n const moduleVersion = await getModuleVersion({\n extractedModule,\n resolveDir: args.resolveDir,\n build,\n });\n if (!moduleVersion) return;\n\n // See if we have an instrumentation registered for this package\n const matchingInstrumentation = getInstrumentation({\n instrumentationModuleDefinitions,\n extractedModule,\n moduleVersion,\n path: args.path,\n });\n if (!matchingInstrumentation) return;\n\n const pluginData: PluginData = {\n extractedModule,\n moduleVersion,\n shouldPatchPackage: true,\n instrumentationName: matchingInstrumentation.name,\n };\n\n return { path, pluginData };\n });\n\n build.onLoad(\n { filter: /.*/ },\n async ({ path, pluginData }: OnLoadArgs) => {\n // Ignore any packages that don't have an instrumentation registered for them\n if (!pluginData?.shouldPatchPackage) return;\n\n const contents = await readFile(path);\n\n const config =\n otelPackageToInstrumentationConfig[pluginData.instrumentationName];\n if (!config) return;\n\n const packageConfig = getPackageConfig({\n pluginConfig,\n oTelInstrumentationPackage: config.oTelInstrumentationPackage,\n });\n const extractedModule = pluginData.extractedModule;\n\n return {\n contents: wrapModule(contents.toString(), {\n path: join(\n extractedModule.package || '',\n extractedModule.path || ''\n ),\n moduleVersion: pluginData.moduleVersion,\n instrumentationName: pluginData.instrumentationName,\n oTelInstrumentationClass: config.oTelInstrumentationClass,\n oTelInstrumentationPackage: config.oTelInstrumentationPackage,\n oTelInstrumentationConstructorArgs:\n config.configGenerator(packageConfig),\n }),\n resolveDir: dirname(path),\n };\n }\n );\n },\n };\n}\n\nfunction getPackageConfig({\n pluginConfig,\n oTelInstrumentationPackage,\n}: {\n pluginConfig?: OpenTelemetryPluginParams;\n oTelInstrumentationPackage: keyof EsbuildInstrumentationConfigMap;\n}) {\n if (!pluginConfig) return;\n if (pluginConfig.instrumentations) {\n const matchingPlugin = pluginConfig.instrumentations.find(\n i => i.instrumentationName === oTelInstrumentationPackage\n );\n if (!matchingPlugin) {\n throw new Error(\n `Instrumentation ${oTelInstrumentationPackage} was found but does not exist in list of instrumentations`\n );\n }\n return matchingPlugin.getConfig();\n }\n return pluginConfig.instrumentationConfig?.[oTelInstrumentationPackage];\n}\n\n/**\n * For a given full path to a module,\n * return the package name it belongs to and the local path to the module\n * input: '/foo/node_modules/@co/stuff/foo/bar/baz.js'\n * output: { package: '@co/stuff', path: 'foo/bar/baz.js' }\n */\nfunction extractPackageAndModulePath(\n originalPath: string,\n resolveDir: string\n): { path: string; extractedModule: ExtractedModule | null } {\n // @see https://github.com/nodejs/node/issues/47000\n const path = require.resolve(\n originalPath === '.' ? './' : originalPath === '..' ? '../' : originalPath,\n { paths: [resolveDir] }\n );\n\n const nodeModulesIndex = path.lastIndexOf(NODE_MODULES);\n if (nodeModulesIndex < 0) return { path, extractedModule: null };\n\n const subPath = path.substring(nodeModulesIndex + NODE_MODULES.length);\n const firstSlashIndex = subPath.indexOf('/');\n\n if (!subPath.startsWith('@')) {\n return {\n path,\n extractedModule: {\n package: subPath.substring(0, firstSlashIndex),\n path: subPath.substring(firstSlashIndex + 1),\n },\n };\n }\n\n const secondSlash = subPath.substring(firstSlashIndex + 1).indexOf('/');\n return {\n path,\n extractedModule: {\n package: subPath.substring(0, firstSlashIndex + secondSlash + 1),\n path: subPath.substring(firstSlashIndex + secondSlash + 2),\n },\n };\n}\n\nfunction shouldIgnoreModule({\n namespace,\n path,\n importer,\n externalModules,\n pathPrefixesToIgnore,\n}: {\n namespace: string;\n path: string;\n importer: string;\n externalModules?: string[];\n pathPrefixesToIgnore?: string[];\n}): boolean {\n // If onLoad is being triggered from another plugin, ignore it\n if (namespace !== 'file') return true;\n // If it's a local import from our code, ignore it\n if (!importer.includes(NODE_MODULES) && path.startsWith('.')) return true;\n // If it starts with a prefix to ignore, ignore it\n if (pathPrefixesToIgnore?.some(prefix => path.startsWith(prefix))) {\n return true;\n }\n // If it's marked as external, ignore it\n if (externalModules?.includes(path)) return true;\n\n return false;\n}\n\nfunction isBuiltIn(path: string, extractedModule: ExtractedModule): boolean {\n return (\n BUILT_INS.has(path) ||\n BUILT_INS.has(`${extractedModule.package}/${extractedModule.path}`)\n );\n}\n\nconst moduleVersionByPackageJsonPath = new Map<string, string>();\n\nasync function getModuleVersion({\n extractedModule,\n resolveDir,\n build,\n}: {\n extractedModule: ExtractedModule;\n resolveDir: string;\n build: PluginBuild;\n}) {\n const path = `${extractedModule.package}/package.json`;\n const contents = moduleVersionByPackageJsonPath.get(path);\n if (contents) return contents;\n\n const { path: packageJsonPath } = await build.resolve(path, {\n resolveDir,\n kind: 'require-resolve',\n });\n if (!packageJsonPath) return;\n\n const packageJsonContents = await readFile(packageJsonPath);\n const moduleVersion = JSON.parse(packageJsonContents.toString()).version;\n moduleVersionByPackageJsonPath.set(path, moduleVersion);\n return moduleVersion;\n}\n\nfunction getInstrumentation({\n instrumentationModuleDefinitions,\n extractedModule,\n path,\n moduleVersion,\n}: {\n instrumentationModuleDefinitions: InstrumentationModuleDefinition[];\n extractedModule: ExtractedModule;\n path: string;\n moduleVersion: string;\n}): InstrumentationModuleDefinition | null {\n for (const instrumentationModuleDefinition of instrumentationModuleDefinitions) {\n const fullModulePath = `${extractedModule.package}/${extractedModule.path}`;\n const nameMatches =\n instrumentationModuleDefinition.name === path ||\n instrumentationModuleDefinition.name === fullModulePath;\n\n if (!nameMatches) {\n const fileMatch = instrumentationModuleDefinition.files.find(file => {\n return file.name === path || file.name === fullModulePath;\n });\n if (!fileMatch) continue;\n }\n\n if (\n instrumentationModuleDefinition.supportedVersions.some(supportedVersion =>\n satisfies(moduleVersion, supportedVersion)\n )\n ) {\n return instrumentationModuleDefinition;\n }\n\n if (\n instrumentationModuleDefinition.files.some(file => {\n if (file.name !== path && file.name !== fullModulePath) return false;\n return file.supportedVersions.some(supportedVersion =>\n satisfies(moduleVersion, supportedVersion)\n );\n })\n ) {\n return instrumentationModuleDefinition;\n }\n }\n return null;\n}\n"]}
|
package/build/src/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OnLoadArgs as EsbuildOnLoadArgs } from 'esbuild';
|
|
2
2
|
import type { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node';
|
|
3
|
+
import { Instrumentation } from '@opentelemetry/instrumentation';
|
|
3
4
|
export interface ExtractedModule {
|
|
4
5
|
package: string;
|
|
5
6
|
path: string;
|
|
@@ -31,6 +32,11 @@ export type EsbuildInstrumentationConfigMap = {
|
|
|
31
32
|
[K in keyof NonBuiltinInstrumentationConfigMap]: RemoveFunctions<NonBuiltinInstrumentationConfigMap[K]>;
|
|
32
33
|
};
|
|
33
34
|
export interface OpenTelemetryPluginParams {
|
|
35
|
+
/**
|
|
36
|
+
* Allow configuring instrumentations loaded from getNodeAutoInstrumentations (from @opentelemetry/auto-instrumentations-node).
|
|
37
|
+
*
|
|
38
|
+
* @deprecated Use `instrumentations` instead and pass in already configured instrumentations
|
|
39
|
+
*/
|
|
34
40
|
instrumentationConfig?: EsbuildInstrumentationConfigMap;
|
|
35
41
|
/** Modules to consider external and ignore from the plugin */
|
|
36
42
|
externalModules?: string[];
|
|
@@ -41,6 +47,44 @@ export interface OpenTelemetryPluginParams {
|
|
|
41
47
|
* root of your project then you could set that here to ignore modules
|
|
42
48
|
*/
|
|
43
49
|
pathPrefixesToIgnore?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Instrumentations to apply
|
|
52
|
+
* Defaults to `getNodeAutoInstrumentations()` from `@opentelemetry/auto-instrumentations-node`.
|
|
53
|
+
* NB: getNodeAutoInstrumentations() can change what it returns (and what is enabled by default) version to version
|
|
54
|
+
* so as this plugin updates dependencies that may change, if you are not manually configuring instrumentations.
|
|
55
|
+
*
|
|
56
|
+
* NB: Not all config options for each instrumentation will be respected. Notably, functions will be ignored
|
|
57
|
+
* as this plugin requires serializing the configs as JSON during bundling which are then read at runtime.
|
|
58
|
+
*
|
|
59
|
+
* This works:
|
|
60
|
+
* ```typescript
|
|
61
|
+
* openTelemetryPlugin({
|
|
62
|
+
* instrumentations: [
|
|
63
|
+
* new PinoInstrumentation({
|
|
64
|
+
* logKeys: {
|
|
65
|
+
* traceId: 'traceId',
|
|
66
|
+
* spanId: 'spanId',
|
|
67
|
+
* traceFlags: 'traceFlags',
|
|
68
|
+
* }
|
|
69
|
+
* })
|
|
70
|
+
* ]
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* This would not (logHook would be ignored)
|
|
75
|
+
* ```typescript
|
|
76
|
+
* openTelemetryPlugin({
|
|
77
|
+
* instrumentations: [
|
|
78
|
+
* new PinoInstrumentation({
|
|
79
|
+
* logHook: (span, record) => {
|
|
80
|
+
* record['resource.service.name'] = provider.resource.attributes['service.name'];
|
|
81
|
+
* }
|
|
82
|
+
* })
|
|
83
|
+
* ]
|
|
84
|
+
* })
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
instrumentations?: Instrumentation[];
|
|
44
88
|
}
|
|
45
89
|
export {};
|
|
46
90
|
//# sourceMappingURL=types.d.ts.map
|
package/build/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { OnLoadArgs as EsbuildOnLoadArgs } from 'esbuild';\nimport type { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node';\n\nexport interface ExtractedModule {\n package: string;\n path: string;\n}\n\nexport type PluginData = {\n extractedModule: ExtractedModule;\n shouldPatchPackage: boolean;\n moduleVersion: string;\n instrumentationName: string;\n};\n\nexport type OnLoadArgs = Omit<EsbuildOnLoadArgs, 'pluginData'> & {\n pluginData?: PluginData;\n};\n\nexport interface ModuleParams {\n path?: string;\n oTelInstrumentationPackage: string;\n oTelInstrumentationClass: string;\n oTelInstrumentationConstructorArgs?: string;\n instrumentationName?: string;\n moduleVersion: string;\n}\n\ntype _RemoveFunctions<T> = {\n [P in keyof T as T[P] extends (...args: unknown[]) => unknown\n ? never\n : P]: T[P];\n};\n\n// _RemoveFunctions does not work on optional fields, so first make the type required then apply Partial to the result\nexport type RemoveFunctions<T> = Partial<_RemoveFunctions<Required<T>>>;\n\ntype BuiltinPackages =\n | '@opentelemetry/instrumentation-dns'\n | '@opentelemetry/instrumentation-fs'\n | '@opentelemetry/instrumentation-http';\n\ntype NonBuiltinInstrumentationConfigMap = Omit<\n InstrumentationConfigMap,\n BuiltinPackages\n>;\n\nexport type EsbuildInstrumentationConfigMap = {\n [K in keyof NonBuiltinInstrumentationConfigMap]: RemoveFunctions<\n NonBuiltinInstrumentationConfigMap[K]\n >;\n};\n\nexport interface OpenTelemetryPluginParams {\n instrumentationConfig?: EsbuildInstrumentationConfigMap;\n\n /** Modules to consider external and ignore from the plugin */\n externalModules?: string[];\n\n /**\n * Path prefixes to ignore.\n *\n * ie if you configure compilerOptions.paths in your tsconfig.json to use something like `~/` for the\n * root of your project then you could set that here to ignore modules\n */\n pathPrefixesToIgnore?: string[];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { OnLoadArgs as EsbuildOnLoadArgs } from 'esbuild';\nimport type { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node';\nimport { Instrumentation } from '@opentelemetry/instrumentation';\n\nexport interface ExtractedModule {\n package: string;\n path: string;\n}\n\nexport type PluginData = {\n extractedModule: ExtractedModule;\n shouldPatchPackage: boolean;\n moduleVersion: string;\n instrumentationName: string;\n};\n\nexport type OnLoadArgs = Omit<EsbuildOnLoadArgs, 'pluginData'> & {\n pluginData?: PluginData;\n};\n\nexport interface ModuleParams {\n path?: string;\n oTelInstrumentationPackage: string;\n oTelInstrumentationClass: string;\n oTelInstrumentationConstructorArgs?: string;\n instrumentationName?: string;\n moduleVersion: string;\n}\n\ntype _RemoveFunctions<T> = {\n [P in keyof T as T[P] extends (...args: unknown[]) => unknown\n ? never\n : P]: T[P];\n};\n\n// _RemoveFunctions does not work on optional fields, so first make the type required then apply Partial to the result\nexport type RemoveFunctions<T> = Partial<_RemoveFunctions<Required<T>>>;\n\ntype BuiltinPackages =\n | '@opentelemetry/instrumentation-dns'\n | '@opentelemetry/instrumentation-fs'\n | '@opentelemetry/instrumentation-http';\n\ntype NonBuiltinInstrumentationConfigMap = Omit<\n InstrumentationConfigMap,\n BuiltinPackages\n>;\n\nexport type EsbuildInstrumentationConfigMap = {\n [K in keyof NonBuiltinInstrumentationConfigMap]: RemoveFunctions<\n NonBuiltinInstrumentationConfigMap[K]\n >;\n};\n\nexport interface OpenTelemetryPluginParams {\n /**\n * Allow configuring instrumentations loaded from getNodeAutoInstrumentations (from @opentelemetry/auto-instrumentations-node).\n *\n * @deprecated Use `instrumentations` instead and pass in already configured instrumentations\n */\n instrumentationConfig?: EsbuildInstrumentationConfigMap;\n\n /** Modules to consider external and ignore from the plugin */\n externalModules?: string[];\n\n /**\n * Path prefixes to ignore.\n *\n * ie if you configure compilerOptions.paths in your tsconfig.json to use something like `~/` for the\n * root of your project then you could set that here to ignore modules\n */\n pathPrefixesToIgnore?: string[];\n\n /**\n * Instrumentations to apply\n * Defaults to `getNodeAutoInstrumentations()` from `@opentelemetry/auto-instrumentations-node`.\n * NB: getNodeAutoInstrumentations() can change what it returns (and what is enabled by default) version to version\n * so as this plugin updates dependencies that may change, if you are not manually configuring instrumentations.\n *\n * NB: Not all config options for each instrumentation will be respected. Notably, functions will be ignored\n * as this plugin requires serializing the configs as JSON during bundling which are then read at runtime.\n *\n * This works:\n * ```typescript\n * openTelemetryPlugin({\n * instrumentations: [\n * new PinoInstrumentation({\n * logKeys: {\n * traceId: 'traceId',\n * spanId: 'spanId',\n * traceFlags: 'traceFlags',\n * }\n * })\n * ]\n * })\n * ```\n *\n * This would not (logHook would be ignored)\n * ```typescript\n * openTelemetryPlugin({\n * instrumentations: [\n * new PinoInstrumentation({\n * logHook: (span, record) => {\n * record['resource.service.name'] = provider.resource.attributes['service.name'];\n * }\n * })\n * ]\n * })\n * ```\n */\n instrumentations?: Instrumentation[];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opentelemetry-esbuild-plugin-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Metapackage which bundles opentelemetry node core and contrib instrumentations via an esbuild plugin",
|
|
5
5
|
"author": "Drew Corlin",
|
|
6
6
|
"homepage": "https://github.com/DrewCorlin/opentelemetry-esbuild-plugin-node",
|
|
@@ -37,40 +37,42 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@fastify/rate-limit": "^10.2.2",
|
|
39
39
|
"@opentelemetry/api": "^1.9.0",
|
|
40
|
-
"@opentelemetry/sdk-node": "^0.57.1",
|
|
41
40
|
"@types/mocha": "7.0.2",
|
|
42
41
|
"@types/node": "^20.17.17",
|
|
43
|
-
"@types/semver": "^7.5.8",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "8.23.0",
|
|
45
|
-
"@typescript-eslint/parser": "8.23.0",
|
|
46
42
|
"eslint": "^8.57.1",
|
|
43
|
+
"@opentelemetry/sdk-node": "^0.200.0",
|
|
44
|
+
"@types/semver": "^7.7.0",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "8.28.0",
|
|
46
|
+
"@typescript-eslint/parser": "8.28.0",
|
|
47
47
|
"eslint-config-airbnb-base": "15.0.0",
|
|
48
|
-
"eslint-config-prettier": "10.
|
|
48
|
+
"eslint-config-prettier": "10.1.1",
|
|
49
49
|
"eslint-plugin-header": "3.1.1",
|
|
50
50
|
"eslint-plugin-import": "2.31.0",
|
|
51
51
|
"eslint-plugin-node": "11.1.0",
|
|
52
|
-
"eslint-plugin-prettier": "5.2.
|
|
53
|
-
"fastify": "5.2.
|
|
52
|
+
"eslint-plugin-prettier": "5.2.5",
|
|
53
|
+
"fastify": "5.2.2",
|
|
54
54
|
"graphql": "^16.10.0",
|
|
55
55
|
"mocha": "7.2.0",
|
|
56
56
|
"mongodb": "6.8.0",
|
|
57
57
|
"mongodb-memory-server": "9.5.0",
|
|
58
58
|
"nyc": "17.1.0",
|
|
59
59
|
"pino": "^9.6.0",
|
|
60
|
-
"prettier": "3.5.
|
|
60
|
+
"prettier": "3.5.3",
|
|
61
61
|
"redis": "^4.7.0",
|
|
62
62
|
"release-it": "^18.1.2",
|
|
63
63
|
"rimraf": "6.0.1",
|
|
64
64
|
"ts-mocha": "10.0.0",
|
|
65
65
|
"ts-node": "^10.9.2",
|
|
66
|
-
"typescript": "5.
|
|
66
|
+
"typescript": "5.8.2"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
70
|
-
"@opentelemetry/instrumentation": "^0.
|
|
71
|
-
"esbuild": "0.25.x",
|
|
69
|
+
"@opentelemetry/auto-instrumentations-node": "^0.57.0",
|
|
70
|
+
"@opentelemetry/instrumentation": "^0.200.0",
|
|
72
71
|
"semver": "^7.7.1"
|
|
73
72
|
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"esbuild": ">=0.21.x <=0.25.x"
|
|
75
|
+
},
|
|
74
76
|
"files": [
|
|
75
77
|
"build/src/**/*.js",
|
|
76
78
|
"build/src/**/*.js.map",
|