Skip to content

Commit

Permalink
Restore filtering by instrumentation name and catch instrumentation e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
RafalSumislawski committed Nov 21, 2024
1 parent 85995ee commit 7f3a539
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
52 changes: 29 additions & 23 deletions packages/esbuild-plugin-node/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function wrapModule(
moduleVersion,
oTelInstrumentationPackage,
oTelInstrumentationClass,
instrumentationName,
oTelInstrumentationConstructorArgs = '',
}: ModuleParams
) {
Expand All @@ -31,37 +32,42 @@ export function wrapModule(
${originalSource}
})(...arguments);
{
let mod = module.exports;
const { satisfies } = require('semver');
const { ${oTelInstrumentationClass} } = require('${oTelInstrumentationPackage}');
const { diag } = require('@opentelemetry/api');
const instrumentations = new ${oTelInstrumentationClass}(${oTelInstrumentationConstructorArgs}).getModuleDefinitions();
for (const instrumentation of instrumentations) {
if (!instrumentation.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {
diag.debug('Skipping instrumentation ${oTelInstrumentationClass}, because module version ${moduleVersion} does not match supported versions ' + instrumentation.supportedVersions.join(','));
continue;
}
try {
let mod = module.exports;
if (instrumentation.patch) {
diag.debug('Applying instrumentation patch ' + instrumentation.name + ' via esbuild-plugin-node');
mod = instrumentation.patch(mod)
}
const { satisfies } = require('semver');
const { ${oTelInstrumentationClass} } = require('${oTelInstrumentationPackage}');
const instrumentations = new ${oTelInstrumentationClass}(${oTelInstrumentationConstructorArgs}).getModuleDefinitions();
for (const instrumentation of instrumentations.filter(i => i.name === '${instrumentationName}')) {
if (!instrumentation.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {
diag.debug('Skipping instrumentation ${instrumentationName}, because module version ${moduleVersion} does not match supported versions ' + instrumentation.supportedVersions.join(','));
continue;
}
if (instrumentation.files?.length) {
for (const file of instrumentation.files.filter(f => f.name === '${path}')) {
if (!file.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {
diag.debug('Skipping instrumentation for ${path}@${moduleVersion} because it does not match supported versions ' + file.supportedVersions.join(','));
continue;
if (instrumentation.patch) {
diag.debug('Applying instrumentation patch ${instrumentationName} via esbuild-plugin-node');
mod = instrumentation.patch(mod)
}
if (instrumentation.files?.length) {
for (const file of instrumentation.files.filter(f => f.name === '${path}')) {
if (!file.supportedVersions.some(v => satisfies('${moduleVersion}', v))) {
diag.debug('Skipping instrumentation for ${path}@${moduleVersion} because it does not match supported versions' + file.supportedVersions.join(','));
continue;
}
diag.debug('Applying instrumentation patch to ${path}@${moduleVersion} via esbuild-plugin-node');
mod = file.patch(mod, '${moduleVersion}');
}
diag.debug('Applying instrumentation patch to ${path}@${moduleVersion} via esbuild-plugin-node');
mod = file.patch(mod, '${moduleVersion}');
}
}
}
module.exports = mod;
module.exports = mod;
} catch (e) {
diag.error('Error applying instrumentation ${instrumentationName}', e);
}
}
`;
}
1 change: 1 addition & 0 deletions packages/esbuild-plugin-node/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function openTelemetryPlugin(
extractedModule.path || ''
),
moduleVersion: pluginData.moduleVersion,
instrumentationName: pluginData.instrumentationName,
oTelInstrumentationClass: config.oTelInstrumentationClass,
oTelInstrumentationPackage: config.oTelInstrumentationPackage,
oTelInstrumentationConstructorArgs:
Expand Down

0 comments on commit 7f3a539

Please sign in to comment.