Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support 'otel:bundle:load' diagnostics_channel message for instrumentation in bundles #4818

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

trentm
Copy link
Contributor

@trentm trentm commented Jun 21, 2024

(This is the core-repo part of a proposed diagnostics_channel-based approach to supporting instrumentation in bundles. There will be a coming contrib-repo PR to add an esbuild-plugin package. More details coming.)

checklist

  • add changelog message (I'm skipping for now to avoid merge conflicts while this is still draft)

@trentm trentm self-assigned this Jun 21, 2024
Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Aug 26, 2024
Copy link

@rossipedia rossipedia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Thanks for your awesome work on this. I was able to try it out on our single-file server build and it worked out great for the most part, but I found one issue with instrumentations that supported multiple versions with the same file path. Only the last one specified would be found in the imdFromHookPath map.

I figured it was probably safe to turn the value type of that map into an array, since calling ._onRequire for a instrumentation file definition that doesn't match the version is essentially a no-op.

I've added the changes I made as suggestions on this PR, hopefully you find it useful. It's working for me and I'm finally able to get trace_id and span_id in my winston logs 💪

Again, thank you so much for this work! Hopefully it makes it into the package proper soon 👍

PS: I also made some performance tweaks to the related esbuild plugin, I'll see about commenting on that PR with those changes later today.

@@ -293,6 +298,9 @@ export abstract class InstrumentationBase<
}

this._warnOnPreloadedModules();

const imdFromHookPath: Map<string, InstrumentationModuleDefinition> =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const imdFromHookPath: Map<string, InstrumentationModuleDefinition> =
const imdsFromHookPath: Map<string, InstrumentationModuleDefinition[]> =

Comment on lines +351 to +352
const imd = imdFromHookPath.get(message.name);
if (!imd) {
Copy link

@rossipedia rossipedia Sep 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const imd = imdFromHookPath.get(message.name);
if (!imd) {
const imds = imdsFromHookPath.get(message.name);
if (!imds) {

Comment on lines +356 to +363
const patchedExports = this._onRequire<typeof exports>(
imd,
message.exports,
message.name,
undefined,
message.version // Package version was determined at bundle-time.
);
message.exports = patchedExports;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const patchedExports = this._onRequire<typeof exports>(
imd,
message.exports,
message.name,
undefined,
message.version // Package version was determined at bundle-time.
);
message.exports = patchedExports;
for (const imd of imds) {
const patchedExports = this._onRequire<typeof exports>(
imd,
message.exports,
message.name,
undefined,
message.version // Package version was determined at bundle-time.
);
message.exports = patchedExports;
}

Comment on lines +327 to +330
imdFromHookPath.set(module.name, module);
for (const file of module.files) {
imdFromHookPath.set(file.name, module);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
imdFromHookPath.set(module.name, module);
for (const file of module.files) {
imdFromHookPath.set(file.name, module);
}
const imdsByModuleName = imdsFromHookPath.get(module.name) ?? [];
imdsFromHookPath.set(module.name, imdsByModuleName);
imdsByModuleName.push(module);
for (const file of module.files) {
const imdsByFileName = imdsFromHookPath.get(file.name) ?? [];
imdsFromHookPath.set(file.name, imdsByFileName);
imdsByFileName.push(module);
}

@github-actions github-actions bot removed the stale label Sep 9, 2024
@drewcorlin1
Copy link
Contributor

@trentm will you be able to incorporate these comments? I'd like to push this along in any way possible

@drewcorlin1
Copy link
Contributor

@trentm any word here? I've been using my own fork of open-telemetry/opentelemetry-js-contrib#1856 in production for about a year now with great results. I really want to get this incorporated upstream to let others leverage it. Once this gets in I'd be happy to take a stab at plugins for other bundlers too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants