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(node): Undici integration #7582

Merged
merged 11 commits into from Mar 27, 2023
Merged

feat(node): Undici integration #7582

merged 11 commits into from Mar 27, 2023

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Mar 23, 2023

ref #6939

ref #7526

This PR adds support for Undici. This is required for us to instrument server-side fetch, introduced with Node 18+!

Requires Undici v4.7.0 and above.

SvelteKit uses Undici for fetch, and this will also help us with Next.js instrumentation.

I keep getting reminded of https://en.wikipedia.org/wiki/Jodeci whenever I work on this.

Follow up tasks: #7624

let ds: typeof DiagnosticsChannel | undefined;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
ds = require('diagnostics_channel') as typeof DiagnosticsChannel;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, because we need to support cjs.

I think that docstring is no longer an issue - but I'll let @Lms24 confirm that.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC await import would actually be transpiled to Promise.resolve(() => require(..)) for our CJS build. The reason why we switched back to require is that only require'd modules are monkey-patchable while imported ones are not. So I'd say we probably can try await import here as we don't monkey-patch the required module.

However, we also don't have to if it the async nature of import makes things harder here. For instance, I ran into timing problems when trying to convert the LocalVariables integration to import and decided to leave it as is and revisit later.

Thanks for the comment link. I need to change the comment as I don't think it actually is true for SvelteKit anymore. I added this comment before I realized that yarn link caused these weird cjs/esm problems in SvelteKit.

Copy link
Member

Choose a reason for hiding this comment

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

IMHO if we can still make it work with import, I'd still do it - the less require we have in our code base, the better!

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Nice! If this is hard to unit-test, maybe we just add integration tests?

packages/node/src/integrations/diagnostics_channel.d.ts Outdated Show resolved Hide resolved
packages/node/src/integrations/undici.ts Outdated Show resolved Hide resolved
packages/node/src/integrations/undici.ts Outdated Show resolved Hide resolved
packages/node/src/integrations/undici.ts Outdated Show resolved Hide resolved
@AbhiPrasad
Copy link
Member Author

Will refactor after DefinitelyTyped/DefinitelyTyped#64879 gets merged in

@AbhiPrasad AbhiPrasad marked this pull request as ready for review March 27, 2023 14:28
@AbhiPrasad
Copy link
Member Author

Validated with
image

Testing this is such a pain, I'm going to do it in a follow-up PR so we can just ship this for now.

Unit tests seem impossible, so integration tests have to be the way. I may even have to make this a e2e test...

@AbhiPrasad
Copy link
Member Author

Extracted out follow up tasks into #7624

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for applying review suggestions!

Yes, let's merge this w/o tests for the moment and add them when we have integration tests.

Also, let's maybe not yet close #7526 as I'm still figuring out #7598 (will add a point to the tasklist)

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) March 27, 2023 15:53
@AbhiPrasad AbhiPrasad merged commit 46f996e into develop Mar 27, 2023
37 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-unidic-fetch branch March 27, 2023 17:47
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.

None yet

3 participants