Skip to content

Commit 85995ee

Browse files
Iterate over instrumentations applying those matching the module version
1 parent b5865a6 commit 85995ee

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

packages/esbuild-plugin-node/src/common.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export function wrapModule(
2323
moduleVersion,
2424
oTelInstrumentationPackage,
2525
oTelInstrumentationClass,
26-
instrumentationName,
2726
oTelInstrumentationConstructorArgs = '',
2827
}: ModuleParams
2928
) {
@@ -39,31 +38,29 @@ export function wrapModule(
3938
const { diag } = require('@opentelemetry/api');
4039
const instrumentations = new ${oTelInstrumentationClass}(${oTelInstrumentationConstructorArgs}).getModuleDefinitions();
4140
42-
if (instrumentations.length > 1 && !'${instrumentationName}') {
43-
diag.error('instrumentationName must be specified because ${oTelInstrumentationClass} has multiple instrumentations');
44-
return;
45-
}
46-
const instrumentation = ${
47-
instrumentationName
48-
? `instrumentations.find(i => i.name === '${instrumentationName}')`
49-
: 'instrumentations[0]'
50-
};
41+
for (const instrumentation of instrumentations) {
42+
if (!instrumentation.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {
43+
diag.debug('Skipping instrumentation ${oTelInstrumentationClass}, because module version ${moduleVersion} does not match supported versions ' + instrumentation.supportedVersions.join(','));
44+
continue;
45+
}
5146
52-
if (instrumentation.patch) {
53-
mod = instrumentation.patch(mod)
54-
}
47+
if (instrumentation.patch) {
48+
diag.debug('Applying instrumentation patch ' + instrumentation.name + ' via esbuild-plugin-node');
49+
mod = instrumentation.patch(mod)
50+
}
5551
56-
if (instrumentation.files?.length) {
57-
for (const file of instrumentation.files.filter(f => f.name === '${path}')) {
58-
if (!file.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {
59-
diag.debug('Skipping instrumentation for ${path}@${moduleVersion} because it does not match supported versions ' + file.supportedVersions.join(','));
60-
continue;
52+
if (instrumentation.files?.length) {
53+
for (const file of instrumentation.files.filter(f => f.name === '${path}')) {
54+
if (!file.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {
55+
diag.debug('Skipping instrumentation for ${path}@${moduleVersion} because it does not match supported versions ' + file.supportedVersions.join(','));
56+
continue;
57+
}
58+
diag.debug('Applying instrumentation patch to ${path}@${moduleVersion} via esbuild-plugin-node');
59+
mod = file.patch(mod, '${moduleVersion}');
6160
}
62-
mod = file.patch(mod, '${moduleVersion}');
6361
}
6462
}
6563
66-
6764
module.exports = mod;
6865
}
6966
`;

packages/esbuild-plugin-node/src/plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ export function openTelemetryPlugin(
118118
extractedModule.path || ''
119119
),
120120
moduleVersion: pluginData.moduleVersion,
121-
instrumentationName: pluginData.instrumentationName,
122121
oTelInstrumentationClass: config.oTelInstrumentationClass,
123122
oTelInstrumentationPackage: config.oTelInstrumentationPackage,
124123
oTelInstrumentationConstructorArgs:

0 commit comments

Comments
 (0)