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(instrumentation): support ESM in node via import-in-the-middle #2640

Closed
wants to merge 1 commit into from

Conversation

bengl
Copy link

@bengl bengl commented Nov 23, 2021

Which problem is this PR solving?

Node.js ESM support.

Short description of the changes

Adds import-in-the-middle alongside require-in-the-middle. Also avoids hanging on to the hooks, because they're unnecessary (not used in disable).

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

The existing tests pass. The part of code that uses require-in-the-middle does not appear to be tested by the test files in the package. Are there other tests elsewhere that cover it? If so, happy to add appropriate tests there. I'll call this a draft until there's something better here.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@@ -17,6 +17,7 @@
import * as types from '../../types';
import * as path from 'path';
import * as RequireInTheMiddle from 'require-in-the-middle';
import ImportInTheMiddle from 'require-in-the-middle';
Copy link
Member

Choose a reason for hiding this comment

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

this should be IITM not RITM right?

Copy link
Author

Choose a reason for hiding this comment

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

Whoops! Fixing this now.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed, I think. 😅

@lizthegrey
Copy link
Member

lizthegrey commented Nov 23, 2021

To answer the question of tests: I know there's full integration tests in https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts#L223 etc. -- that verify spans are created when instrumentation is hooked, you'd just need to run under ESM in order to force the import to happen with ESM rather than it being converted to a require.

Likewise https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/http.ts#L86 is exercised by https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts

@@ -29,7 +30,7 @@ export abstract class InstrumentationBase<T = any>
extends InstrumentationAbstract
implements types.Instrumentation {
private _modules: InstrumentationModuleDefinition<T>[];
private _hooks: RequireInTheMiddle.Hooked[] = [];
private _hooks = 0;
Copy link
Member

Choose a reason for hiding this comment

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

i think we can remove this altogether and only use _enabled ?

@vmarchaud
Copy link
Member

I've launched the tests suite for the PR and it seems there are issue with our typescript config, do you think you could look into it ?

@codecov
Copy link

codecov bot commented Nov 24, 2021

Codecov Report

Merging #2640 (14f5b90) into main (5e9c7e1) will increase coverage by 0.91%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #2640      +/-   ##
==========================================
+ Coverage   93.10%   94.02%   +0.91%     
==========================================
  Files         123       76      -47     
  Lines        4758     2409    -2349     
  Branches     1061      549     -512     
==========================================
- Hits         4430     2265    -2165     
+ Misses        328      144     -184     
Impacted Files Coverage Δ
...pentelemetry-exporter-trace-otlp-http/src/types.ts
...ry-instrumentation-grpc/src/grpc-js/clientUtils.ts
...-instrumentation-fetch/src/enums/AttributeNames.ts
...exporter-metrics-otlp-http/src/transformMetrics.ts
...elemetry-instrumentation-grpc/src/grpc-js/index.ts
...emetry-instrumentation-xml-http-request/src/xhr.ts
...es/opentelemetry-instrumentation-http/src/utils.ts
...mentation-xml-http-request/src/enums/EventNames.ts
...etry-exporter-prometheus/src/PrometheusExporter.ts
...ry-sdk-metrics-base/src/view/InstrumentSelector.ts
... and 37 more

@github-actions
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 Jan 24, 2022
@lizthegrey
Copy link
Member

Please keep this open, I think this feature should be still considered for adoption.

lizthegrey added a commit to honeycombio/opentelemetry-js that referenced this pull request Feb 4, 2022
@lizthegrey
Copy link
Member

I've rebased this as #2763

@itssumitrai
Copy link

Any Update on this ? we would also like to have ESM support

@Kampe
Copy link

Kampe commented Apr 25, 2022

Would LOVE to see this get pulled in, this is massive!

@pichlermarc
Copy link
Member

Completed in #3698, huge thanks to everyone involved 🙂

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.

None yet

7 participants