opentelemetry-esbuild-plugin-node 1.0.2 → 2.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright The OpenTelemetry Authors
3
+ * Copyright The Authors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.wrapModule = void 0;
18
+ exports.wrapModule = wrapModule;
19
19
  function wrapModule(originalSource, { path, moduleVersion, oTelInstrumentationPackage, oTelInstrumentationClass, instrumentationName, oTelInstrumentationConstructorArgs = '', }) {
20
20
  return `
21
21
  (function() {
@@ -61,5 +61,4 @@ function wrapModule(originalSource, { path, moduleVersion, oTelInstrumentationPa
61
61
  }
62
62
  `;
63
63
  }
64
- exports.wrapModule = wrapModule;
65
64
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,SAAgB,UAAU,CACxB,cAAsB,EACtB,EACE,IAAI,EACJ,aAAa,EACb,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,kCAAkC,GAAG,EAAE,GAC1B;IAEf,OAAO;;IAEL,cAAc;;;;;;;;;cASJ,wBAAwB,iBAAiB,0BAA0B;mCAC9C,wBAAwB,IAAI,kCAAkC;;6EAEpB,mBAAmB;oEAC5B,aAAa;+CAClC,mBAAmB,4BAA4B,aAAa;;;;;qDAKtD,mBAAmB;;;;;2EAKG,IAAI;6DAClB,aAAa;uDACnB,IAAI,IAAI,aAAa;;;0DAGlB,IAAI,IAAI,aAAa;mCAC5C,aAAa;;;;;;;iDAOC,mBAAmB;;;CAGnE,CAAC;AACF,CAAC;AAtDD,gCAsDC","sourcesContent":["/*\n * Copyright The OpenTelemetry 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 { ModuleParams } from './types';\n\nexport function wrapModule(\n originalSource: string,\n {\n path,\n moduleVersion,\n oTelInstrumentationPackage,\n oTelInstrumentationClass,\n instrumentationName,\n oTelInstrumentationConstructorArgs = '',\n }: ModuleParams\n) {\n return `\n(function() {\n ${originalSource}\n})(...arguments);\n{\n const { diag } = require('@opentelemetry/api');\n\n try {\n let mod = module.exports;\n\n const { satisfies } = require('semver');\n const { ${oTelInstrumentationClass} } = require('${oTelInstrumentationPackage}');\n const instrumentations = new ${oTelInstrumentationClass}(${oTelInstrumentationConstructorArgs}).getModuleDefinitions();\n\n for (const instrumentation of instrumentations.filter(i => i.name === '${instrumentationName}')) {\n if (!instrumentation.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {\n diag.debug('Skipping instrumentation ${instrumentationName}, because module version ${moduleVersion} does not match supported versions ' + instrumentation.supportedVersions.join(','));\n continue;\n }\n\n if (instrumentation.patch) {\n diag.debug('Applying instrumentation patch ${instrumentationName} via esbuild-plugin-node');\n mod = instrumentation.patch(mod)\n }\n\n if (instrumentation.files?.length) {\n for (const file of instrumentation.files.filter(f => f.name === '${path}')) {\n if (!file.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {\n diag.debug('Skipping instrumentation for ${path}@${moduleVersion} because it does not match supported versions' + file.supportedVersions.join(','));\n continue;\n }\n diag.debug('Applying instrumentation patch to ${path}@${moduleVersion} via esbuild-plugin-node');\n mod = file.patch(mod, '${moduleVersion}');\n }\n }\n }\n\n module.exports = mod;\n } catch (e) {\n diag.error('Error applying instrumentation ${instrumentationName}', e);\n }\n}\n`;\n}\n"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAIH,gCAsDC;AAtDD,SAAgB,UAAU,CACxB,cAAsB,EACtB,EACE,IAAI,EACJ,aAAa,EACb,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,kCAAkC,GAAG,EAAE,GAC1B;IAEf,OAAO;;IAEL,cAAc;;;;;;;;;cASJ,wBAAwB,iBAAiB,0BAA0B;mCAC9C,wBAAwB,IAAI,kCAAkC;;6EAEpB,mBAAmB;oEAC5B,aAAa;+CAClC,mBAAmB,4BAA4B,aAAa;;;;;qDAKtD,mBAAmB;;;;;2EAKG,IAAI;6DAClB,aAAa;uDACnB,IAAI,IAAI,aAAa;;;0DAGlB,IAAI,IAAI,aAAa;mCAC5C,aAAa;;;;;;;iDAOC,mBAAmB;;;CAGnE,CAAC;AACF,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 type { ModuleParams } from './types';\n\nexport function wrapModule(\n originalSource: string,\n {\n path,\n moduleVersion,\n oTelInstrumentationPackage,\n oTelInstrumentationClass,\n instrumentationName,\n oTelInstrumentationConstructorArgs = '',\n }: ModuleParams\n) {\n return `\n(function() {\n ${originalSource}\n})(...arguments);\n{\n const { diag } = require('@opentelemetry/api');\n\n try {\n let mod = module.exports;\n\n const { satisfies } = require('semver');\n const { ${oTelInstrumentationClass} } = require('${oTelInstrumentationPackage}');\n const instrumentations = new ${oTelInstrumentationClass}(${oTelInstrumentationConstructorArgs}).getModuleDefinitions();\n\n for (const instrumentation of instrumentations.filter(i => i.name === '${instrumentationName}')) {\n if (!instrumentation.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {\n diag.debug('Skipping instrumentation ${instrumentationName}, because module version ${moduleVersion} does not match supported versions ' + instrumentation.supportedVersions.join(','));\n continue;\n }\n\n if (instrumentation.patch) {\n diag.debug('Applying instrumentation patch ${instrumentationName} via esbuild-plugin-node');\n mod = instrumentation.patch(mod)\n }\n\n if (instrumentation.files?.length) {\n for (const file of instrumentation.files.filter(f => f.name === '${path}')) {\n if (!file.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {\n diag.debug('Skipping instrumentation for ${path}@${moduleVersion} because it does not match supported versions' + file.supportedVersions.join(','));\n continue;\n }\n diag.debug('Applying instrumentation patch to ${path}@${moduleVersion} via esbuild-plugin-node');\n mod = file.patch(mod, '${moduleVersion}');\n }\n }\n }\n\n module.exports = mod;\n } catch (e) {\n diag.error('Error applying instrumentation ${instrumentationName}', e);\n }\n}\n`;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright The OpenTelemetry Authors
3
+ * Copyright The Authors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+BAA4D;AAAnD,0HAAA,kCAAkC,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry 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 { otelPackageToInstrumentationConfig } from './main';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,+BAA4D;AAAnD,0HAAA,kCAAkC,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 { otelPackageToInstrumentationConfig } from './main';\n"]}
@@ -5,14 +5,14 @@ export declare function getOtelPackageToInstrumentationConfig(): Record<string,
5
5
  oTelInstrumentationPackage: keyof EsbuildInstrumentationConfigMap;
6
6
  oTelInstrumentationClass: string;
7
7
  configGenerator: <T extends {
8
- enabled?: boolean | undefined;
9
- }>(config?: T | undefined) => string | undefined;
8
+ enabled?: boolean;
9
+ }>(config?: T) => string | undefined;
10
10
  }>;
11
11
  export declare const otelPackageToInstrumentationConfig: Record<string, {
12
12
  oTelInstrumentationPackage: keyof EsbuildInstrumentationConfigMap;
13
13
  oTelInstrumentationClass: string;
14
14
  configGenerator: <T extends {
15
- enabled?: boolean | undefined;
16
- }>(config?: T | undefined) => string | undefined;
15
+ enabled?: boolean;
16
+ }>(config?: T) => string | undefined;
17
17
  }>;
18
18
  //# sourceMappingURL=main.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright The OpenTelemetry Authors
3
+ * Copyright The Authors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -15,7 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.otelPackageToInstrumentationConfig = exports.getOtelPackageToInstrumentationConfig = exports.instrumentationModuleDefinitions = void 0;
18
+ exports.otelPackageToInstrumentationConfig = exports.instrumentationModuleDefinitions = void 0;
19
+ exports.getOtelPackageToInstrumentationConfig = getOtelPackageToInstrumentationConfig;
19
20
  const instrumentation_1 = require("@opentelemetry/instrumentation");
20
21
  const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
21
22
  const instrumentations = (0, auto_instrumentations_node_1.getNodeAutoInstrumentations)();
@@ -52,6 +53,5 @@ function getOtelPackageToInstrumentationConfig() {
52
53
  }
53
54
  return otelPackageToInstrumentationConfig;
54
55
  }
55
- exports.getOtelPackageToInstrumentationConfig = getOtelPackageToInstrumentationConfig;
56
56
  exports.otelPackageToInstrumentationConfig = getOtelPackageToInstrumentationConfig();
57
57
  //# sourceMappingURL=main.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/config/main.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,oEAIwC;AAGxC,0FAAwF;AAExF,MAAM,gBAAgB,GAAG,IAAA,wDAA2B,GAAE,CAAC;AACvD,MAAM,qDAAqD,GACzD,MAAM,CAAC,WAAW,CAChB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AAES,QAAA,gCAAgC,GAAG,MAAM,CAAC,MAAM,CAC3D,qDAAqD,CACtD,CAAC,IAAI,EAAE,CAAC;AAET,SAAS,oBAAoB,CAC3B,eAAgC;;IAEhC,IAAI,eAAe,YAAY,qCAAmB,EAAE;QAClD,OAAO,MAAA,eAAe,CAAC,oBAAoB,EAAE,mCAAI,EAAE,CAAC;KACrD;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;IACnD,MAAM,kCAAkC,GASpC,EAAE,CAAC;IACP,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;QAC9C,MAAM,iBAAiB,GACrB,qDAAqD,CACnD,eAAe,CAAC,mBAAmB,CACpC,CAAC;QAEJ,KAAK,MAAM,+BAA+B,IAAI,iBAAiB,EAAE;YAC/D,uGAAuG;YACvG,8CAA8C;YAC9C,IAAI,eAAe,CAAC,WAAW,CAAC,IAAI,KAAK,iBAAiB;gBAAE,SAAS;YACrE,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;SACL;KACF;IACD,OAAO,kCAAkC,CAAC;AAC5C,CAAC;AA/BD,sFA+BC;AAEY,QAAA,kCAAkC,GAC7C,qCAAqC,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry 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';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\n\nconst instrumentations = getNodeAutoInstrumentations();\nconst instrumentationModuleDefinitionsByInstrumentationName =\n Object.fromEntries(\n instrumentations.map(i => [i.instrumentationName, getModuleDefinitions(i)])\n );\n\nexport const instrumentationModuleDefinitions = Object.values(\n instrumentationModuleDefinitionsByInstrumentationName\n).flat();\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 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 // For some reason @opentelemetry/instrumentation-generic-pool reports its name as just Instrumentation\n // TODO: See if this goes away with an upgrade\n if (instrumentation.constructor.name === 'Instrumentation') continue;\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 otelPackageToInstrumentationConfig;\n}\n\nexport const otelPackageToInstrumentationConfig =\n getOtelPackageToInstrumentationConfig();\n"]}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/config/main.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AA0CH,sFA+BC;AAvED,oEAIwC;AAGxC,0FAAwF;AAExF,MAAM,gBAAgB,GAAG,IAAA,wDAA2B,GAAE,CAAC;AACvD,MAAM,qDAAqD,GACzD,MAAM,CAAC,WAAW,CAChB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;AAES,QAAA,gCAAgC,GAAG,MAAM,CAAC,MAAM,CAC3D,qDAAqD,CACtD,CAAC,IAAI,EAAE,CAAC;AAET,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;IACnD,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,uGAAuG;YACvG,8CAA8C;YAC9C,IAAI,eAAe,CAAC,WAAW,CAAC,IAAI,KAAK,iBAAiB;gBAAE,SAAS;YACrE,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,kCAAkC,CAAC;AAC5C,CAAC;AAEY,QAAA,kCAAkC,GAC7C,qCAAqC,EAAE,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';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\n\nconst instrumentations = getNodeAutoInstrumentations();\nconst instrumentationModuleDefinitionsByInstrumentationName =\n Object.fromEntries(\n instrumentations.map(i => [i.instrumentationName, getModuleDefinitions(i)])\n );\n\nexport const instrumentationModuleDefinitions = Object.values(\n instrumentationModuleDefinitionsByInstrumentationName\n).flat();\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 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 // For some reason @opentelemetry/instrumentation-generic-pool reports its name as just Instrumentation\n // TODO: See if this goes away with an upgrade\n if (instrumentation.constructor.name === 'Instrumentation') continue;\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 otelPackageToInstrumentationConfig;\n}\n\nexport const otelPackageToInstrumentationConfig =\n getOtelPackageToInstrumentationConfig();\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright The OpenTelemetry Authors
3
+ * Copyright The Authors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry 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 { EsbuildInstrumentationConfigMap } from '../types';\n\nexport interface InstrumentationConfig<\n T extends keyof EsbuildInstrumentationConfigMap\n> {\n oTelInstrumentationPackage: T;\n oTelInstrumentationClass: string;\n configGenerator: (\n config?: EsbuildInstrumentationConfigMap[T]\n ) => string | undefined;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/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 { EsbuildInstrumentationConfigMap } from '../types';\n\nexport interface InstrumentationConfig<\n T extends keyof EsbuildInstrumentationConfigMap,\n> {\n oTelInstrumentationPackage: T;\n oTelInstrumentationClass: string;\n configGenerator: (\n config?: EsbuildInstrumentationConfigMap[T]\n ) => string | undefined;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright The OpenTelemetry Authors
3
+ * Copyright The Authors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,mCAA+C;AAAtC,6GAAA,mBAAmB,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry 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 { openTelemetryPlugin } from './plugin';\nexport { OpenTelemetryPluginParams } from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,mCAA+C;AAAtC,6GAAA,mBAAmB,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 { openTelemetryPlugin } from './plugin';\nexport { OpenTelemetryPluginParams } from './types';\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright The OpenTelemetry Authors
3
+ * Copyright The Authors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.openTelemetryPlugin = void 0;
18
+ exports.openTelemetryPlugin = openTelemetryPlugin;
19
19
  const path_1 = require("path");
20
20
  const main_1 = require("./config/main");
21
21
  const module_1 = require("module");
@@ -45,7 +45,7 @@ function openTelemetryPlugin(pluginConfig) {
45
45
  path = result.path;
46
46
  extractedModule = result.extractedModule;
47
47
  }
48
- catch (e) {
48
+ catch (_a) {
49
49
  // Some libraries like `mongodb` require optional dependencies, which may not be present and their absence doesn't break the code
50
50
  // Currently esbuild doesn't provide any better way to handle this in plugins: https://github.com/evanw/esbuild/issues/1127
51
51
  }
@@ -104,7 +104,6 @@ function openTelemetryPlugin(pluginConfig) {
104
104
  },
105
105
  };
106
106
  }
107
- exports.openTelemetryPlugin = openTelemetryPlugin;
108
107
  /**
109
108
  * For a given full path to a module,
110
109
  * return the package name it belongs to and the local path to the module
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AASH,+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,eAAe,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,eAAe;oBAC9C,oBAAoB,EAAE,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,oBAAoB;iBACzD,CAAC,EACF;oBACA,OAAO;iBACR;gBAED,IAAI,IAAI,CAAC;gBACT,IAAI,eAAe,CAAC;gBAEpB,IAAI;oBACF,MAAM,MAAM,GAAG,2BAA2B,CACxC,IAAI,CAAC,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I,EACJ,aAAa,GAKd;IACC,KAAK,MAAM,+BAA+B,IAAI,uCAAgC,EAAE;QAC9E,MAAM,cAAc,GAAG,GAAG,eAAe,CAAC,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,CAAC;QAC5E,MAAM,WAAW,GACf,+BAA+B,CAAC,IAAI,KAAK,IAAI;YAC7C,+BAA+B,CAAC,IAAI,KAAK,cAAc,CAAC;QAE1D,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,SAAS,GAAG,+BAA+B,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAClE,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC;YAC5D,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,SAAS;gBAAE,SAAS;SAC1B;QAED,IACE,+BAA+B,CAAC,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CACxE,IAAA,kBAAS,EAAC,aAAa,EAAE,gBAAgB,CAAC,CAC3C,EACD;YACA,OAAO,+BAA+B,CAAC;SACxC;QAED,IACE,+BAA+B,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAChD,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,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;YACA,OAAO,+BAA+B,CAAC;SACxC;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry 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 (e) {\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;;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,eAAe,EA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,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"]}
@@ -4,13 +4,13 @@ export interface ExtractedModule {
4
4
  package: string;
5
5
  path: string;
6
6
  }
7
- export declare type PluginData = {
7
+ export type PluginData = {
8
8
  extractedModule: ExtractedModule;
9
9
  shouldPatchPackage: boolean;
10
10
  moduleVersion: string;
11
11
  instrumentationName: string;
12
12
  };
13
- export declare type OnLoadArgs = Omit<EsbuildOnLoadArgs, 'pluginData'> & {
13
+ export type OnLoadArgs = Omit<EsbuildOnLoadArgs, 'pluginData'> & {
14
14
  pluginData?: PluginData;
15
15
  };
16
16
  export interface ModuleParams {
@@ -21,13 +21,13 @@ export interface ModuleParams {
21
21
  instrumentationName?: string;
22
22
  moduleVersion: string;
23
23
  }
24
- declare type _RemoveFunctions<T> = {
24
+ type _RemoveFunctions<T> = {
25
25
  [P in keyof T as T[P] extends (...args: unknown[]) => unknown ? never : P]: T[P];
26
26
  };
27
- export declare type RemoveFunctions<T> = Partial<_RemoveFunctions<Required<T>>>;
28
- declare type BuiltinPackages = '@opentelemetry/instrumentation-dns' | '@opentelemetry/instrumentation-fs' | '@opentelemetry/instrumentation-http';
29
- declare type NonBuiltinInstrumentationConfigMap = Omit<InstrumentationConfigMap, BuiltinPackages>;
30
- export declare type EsbuildInstrumentationConfigMap = {
27
+ export type RemoveFunctions<T> = Partial<_RemoveFunctions<Required<T>>>;
28
+ type BuiltinPackages = '@opentelemetry/instrumentation-dns' | '@opentelemetry/instrumentation-fs' | '@opentelemetry/instrumentation-http';
29
+ type NonBuiltinInstrumentationConfigMap = Omit<InstrumentationConfigMap, BuiltinPackages>;
30
+ export type EsbuildInstrumentationConfigMap = {
31
31
  [K in keyof NonBuiltinInstrumentationConfigMap]: RemoveFunctions<NonBuiltinInstrumentationConfigMap[K]>;
32
32
  };
33
33
  export interface OpenTelemetryPluginParams {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright The OpenTelemetry Authors
3
+ * Copyright The Authors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry 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';\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opentelemetry-esbuild-plugin-node",
3
- "version": "1.0.2",
3
+ "version": "2.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",
@@ -35,41 +35,41 @@
35
35
  "url": "https://github.com/DrewCorlin/opentelemetry-esbuild-plugin-node/issues"
36
36
  },
37
37
  "devDependencies": {
38
- "@fastify/rate-limit": "^9.1.0",
38
+ "@fastify/rate-limit": "^10.2.2",
39
39
  "@opentelemetry/api": "^1.9.0",
40
- "@opentelemetry/sdk-node": "^0.55.0",
40
+ "@opentelemetry/sdk-node": "^0.57.1",
41
41
  "@types/mocha": "7.0.2",
42
- "@types/node": "18.6.5",
42
+ "@types/node": "^20.17.17",
43
43
  "@types/semver": "^7.5.8",
44
- "@typescript-eslint/eslint-plugin": "5.8.1",
45
- "@typescript-eslint/parser": "5.8.1",
46
- "eslint": "8.7.0",
44
+ "@typescript-eslint/eslint-plugin": "8.23.0",
45
+ "@typescript-eslint/parser": "8.23.0",
46
+ "eslint": "^8.57.1",
47
47
  "eslint-config-airbnb-base": "15.0.0",
48
- "eslint-config-prettier": "8.8.0",
48
+ "eslint-config-prettier": "10.0.1",
49
49
  "eslint-plugin-header": "3.1.1",
50
- "eslint-plugin-import": "2.27.5",
50
+ "eslint-plugin-import": "2.31.0",
51
51
  "eslint-plugin-node": "11.1.0",
52
- "eslint-plugin-prettier": "4.2.1",
53
- "fastify": "4.15.0",
52
+ "eslint-plugin-prettier": "5.2.3",
53
+ "fastify": "5.2.1",
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
- "nyc": "15.1.0",
59
- "pino": "^8.19.0",
60
- "prettier": "2.8.8",
58
+ "nyc": "17.1.0",
59
+ "pino": "^9.6.0",
60
+ "prettier": "3.5.0",
61
61
  "redis": "^4.7.0",
62
- "release-it": "^17.11.0",
63
- "rimraf": "5.0.5",
62
+ "release-it": "^18.1.2",
63
+ "rimraf": "6.0.1",
64
64
  "ts-mocha": "10.0.0",
65
65
  "ts-node": "^10.9.2",
66
- "typescript": "4.4.4"
66
+ "typescript": "5.7.3"
67
67
  },
68
68
  "dependencies": {
69
- "@opentelemetry/auto-instrumentations-node": "0.53.0",
70
- "@opentelemetry/instrumentation": "^0.55.0",
71
- "esbuild": "0.24.x",
72
- "semver": "^7.6.3"
69
+ "@opentelemetry/auto-instrumentations-node": "^0.56.0",
70
+ "@opentelemetry/instrumentation": "^0.57.1",
71
+ "esbuild": "0.25.x",
72
+ "semver": "^7.7.1"
73
73
  },
74
74
  "files": [
75
75
  "build/src/**/*.js",