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

fix(fastify): Make sure consturctor patching works with esm #1624

Merged
merged 6 commits into from
Aug 29, 2023

Conversation

mydea
Copy link
Contributor

@mydea mydea commented Aug 7, 2023

Which problem is this PR solving?

instrumentation-fastify does not work in ESM mode. This PR fixes this so that fastify can be instrumented when using esm.

The underlying problem is that in ESM mode, the moduleExports is not === the fastify constructor. Instead, this can only be found under the default key.

Short description of the changes

This changes the wrapping behavior to always use the named fastify export, which should always exist.

Fixes #1519

@mydea mydea requested a review from a team August 7, 2023 07:34
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 7, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@Flarna
Copy link
Member

Flarna commented Aug 7, 2023

Is there an impact to commonjs users using fastify like this (copied from fastify docs)?

const fastify = require('fastify')({
  logger: true
})

@mydea
Copy link
Contributor Author

mydea commented Aug 7, 2023

Is there an impact to commonjs users using fastify like this (copied from fastify docs)?

const fastify = require('fastify')({
  logger: true
})

I've tried it in a small test app of mine where both syntaxes continue to work for CJS, but would appreciate if somebody else could also give it a go (due to the "mysterious" ways that these things sometimes work 😅 )

@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Merging #1624 (cbf00b2) into main (d9cd8d7) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1624   +/-   ##
=======================================
  Coverage   91.77%   91.77%           
=======================================
  Files         139      139           
  Lines        7112     7112           
  Branches     1427     1427           
=======================================
  Hits         6527     6527           
  Misses        585      585           
Files Changed Coverage Δ
...try-instrumentation-fastify/src/instrumentation.ts 97.60% <100.00%> (ø)

@pichlermarc
Copy link
Member

@mydea thank you for your contribution. Would you mind signing the CLA? Then we can proceed with the PR. 🙂

@mydea
Copy link
Contributor Author

mydea commented Aug 10, 2023

@mydea thank you for your contribution. Would you mind signing the CLA? Then we can proceed with the PR. 🙂

Done!

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Is there an impact to commonjs users using fastify like this (copied from fastify docs)?

const fastify = require('fastify')({
  logger: true
})

I've tried it in a small test app of mine where both syntaxes continue to work for CJS, but would appreciate if somebody else could also give it a go (due to the "mysterious" ways that these things sometimes work 😅 )

Looks good, thanks! 🙂 I also checked and it seems to work for me too.

It seems to need some adjustments so that prettier succeeds, though (see here, you can also run npm run lint from the plugins/node/opentelemetry-instrumentation-fastify/ to check locally), then this should be good to go 🙂

@mydea
Copy link
Contributor Author

mydea commented Aug 29, 2023

Is there an impact to commonjs users using fastify like this (copied from fastify docs)?

const fastify = require('fastify')({
  logger: true
})

I've tried it in a small test app of mine where both syntaxes continue to work for CJS, but would appreciate if somebody else could also give it a go (due to the "mysterious" ways that these things sometimes work 😅 )

Looks good, thanks! 🙂 I also checked and it seems to work for me too.

It seems to need some adjustments so that prettier succeeds, though (see here, you can also run npm run lint from the plugins/node/opentelemetry-instrumentation-fastify/ to check locally), then this should be good to go 🙂

ah, right, I ran npm run lint:fix and pushed the fix!

@blumamir blumamir merged commit 67f66d2 into open-telemetry:main Aug 29, 2023
13 checks passed
@dyladan dyladan mentioned this pull request Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

instrumentation-fastify fails to initialise if "type" is set to "module" in package.json
4 participants