Skip to content

Conversation

@abhilash-sivan
Copy link
Contributor

@abhilash-sivan abhilash-sivan commented Mar 27, 2025

refs INSTA-12542

This PR sets the new express v5(tagged next major release) as latest version for express in our SDK.
The plan is to adapt v5 for the tests upon release. So till then we will keep the tests to run against express v4.

Express released 5.1.0:

github: https://github.com/expressjs/express/releases/tag/v5.1.0
see npm: https://www.npmjs.com/package/express?activeTab=versions

];
expect(spanNames).to.have.members(expectedSpanNames);
expect(spans.length).to.eql(7);
expect(spanNames).to.eql(spans.map(s => s.data.operation));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The OpenTelemetry sampler runs on Express v5 because our local dependencies include Express v5, and the @opentelemetry/auto-instrumentations-node package indirectly depends on the express package.

@opentelemetry/auto-instrumentations-node is a meta-package that bundles multiple auto-instrumentation libraries, including @opentelemetry/instrumentation-express.

Rather than overriding it with Express v4 and updating to v5 later, we can adapt the tests to v5 now. Changes have been made accordingly.

@abhilash-sivan abhilash-sivan changed the title feat: add express v5 support in currency feat: add express v5 support in currency report Mar 27, 2025
@abhilash-sivan abhilash-sivan added WIP and removed WIP labels Mar 27, 2025
@abhilash-sivan abhilash-sivan marked this pull request as ready for review March 27, 2025 13:57
@abhilash-sivan abhilash-sivan requested a review from a team as a code owner March 27, 2025 13:57
Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

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

This is not a feature.

Where is the express v5 test? Could you add a comment please? THanks

@abhilash-sivan
Copy link
Contributor Author

@kirrg001
Copy link
Contributor

test pointing to v5:
https://github.com/instana/nodejs/pull/1654/files#diff-ceefa79116448c6868e8ea3461511bb6c341754ed3293cd655639ea6f6449801R20

The link does not open for me. Could you pls add a comment on the target test? Thanks!

@abhilash-sivan abhilash-sivan changed the title feat: add express v5 support in currency report feat: added support for express v5 Mar 28, 2025
];
expect(spanNames).to.have.members(expectedSpanNames);
expect(spans.length).to.eql(7);
expect(spanNames).to.eql(spans.map(s => s.data.operation));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The OpenTelemetry sampler runs on Express v5 because our local dependencies include Express v5, and the @opentelemetry/auto-instrumentations-node package indirectly depends on the express package.

@opentelemetry/auto-instrumentations-node is a meta-package that bundles multiple auto-instrumentation libraries, including @opentelemetry/instrumentation-express.

Rather than overriding it with Express v4 and updating to v5 later, we can adapt the tests to v5 now. Changes have been made accordingly.

];
expect(spanNames).to.have.members(expectedSpanNames);
expect(resp.spans.length).to.be.gte(7);
// NOTE: middleware spans are not collected when migrating to express v5 because:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The OpenTelemetry sampler runs on Express v5 because our local dependencies include Express v5, and the @opentelemetry/auto-instrumentations-node package indirectly depends on the express package.

@opentelemetry/auto-instrumentations-node is a meta-package that bundles multiple auto-instrumentation libraries, including @opentelemetry/instrumentation-express.

Rather than overriding it with Express v4 and updating to v5 later, we can adapt the tests to v5 now. Changes have been made accordingly.

// EXIT www.example.com
// 2 x express middleware, 1 x request handler
// 1 x tlc connect, 1 x tls connect
expectExactlyNMatching(spans, 6, [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The OpenTelemetry exporter runs on Express v5 because our local dependencies include Express v5, and the @opentelemetry/auto-instrumentations-node package indirectly depends on the express package.

@opentelemetry/auto-instrumentations-node is a meta-package that bundles multiple auto-instrumentation libraries, including @opentelemetry/instrumentation-express.

Rather than overriding it with Express v4 and updating to v5 later, we can adapt the tests to v5 now. Changes have been made accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why did the request handler disappear?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we use the loadExpressV4 mock for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why did the request handler disappear?

I beleive it is also because of some changes in the v5. I have no resources to point to at this moment. will update.

Why don't we use the loadExpressV4 mock for now?

Already discussed. #1654 (comment)

}

latestVersion = utils.getLatestVersion(currency.name, installedVersion);
latestVersion = utils.getLatestVersion({
Copy link
Contributor

Choose a reason for hiding this comment

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

We no longer need this. Express is latest now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the beta flag for Express but kept this logic for general use cases, even though we don't have any at the moment!

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. Could you pls extract these from this PR and create a new PR? Thanks

});

require('./mockVersion');
require('@instana/core/test/test_util/load_express_v4');
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong

require('./mockVersion');
require('@instana/core/test/test_util/load_express_v4');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Corrected!

process.exit(0);
});

require('@instana/core/test/test_util/load_express_v4');
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: This test needs to run against v4 and v5. You can copy the iteration from the official express test and just just a local mock version file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

sendToParent: require('./sendToParent'),
stringifyItems: require('./stringifyItems'),
mockRequire: require('./mockRequire'),
load_express_v4: require('./load_express_v4'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Camelcase vs underscore consistency.


requireHook.init({ logger: testUtils.createFakeLogger() });
const pattern = requireHook.buildFileNamePattern(['node_modules', 'express', 'lib', 'router', 'route.js']);
// Adapt express v5: it has some changes in the folder structure
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please update this comment and put v4 and v5 latest version links to the file on github? Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

require('./tracing');

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: Why don't we use the loadExpressV4 mock for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even with the mock, this will run on Express v5 because:

  • @opentelemetry/auto-instrumentations-node is a dependency in our package.

  • It depends on @opentelemetry/instrumentation-express, which in turn depends on express.

  • AFAIK, this dependency resolves to our local node_modules since we already have express in our root dependencies.

So, it will run on v5 regardless, which aligns with our need to use v5.

Copy link
Contributor

Choose a reason for hiding this comment

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

NPM should load express v4, because @opentelemetry/instrumentation-express depends on v4.

:( But it does not

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see. @opentelemetry/instrumentation-express has no peer or prod dependency on express. Thats why

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we use overrides for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think so.
But do we need it ? Because we want to anyway update to v5.

If we override this, then we will have to revert it back in the v5 test update

Copy link
Contributor

Choose a reason for hiding this comment

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

We ship the exporter with a specific pinned version for Otel

"@instana/serverless": "4.9.0",

"@opentelemetry/api": "1.4.1",
"@opentelemetry/core": "1.17.1"

As long as we still test against the right conditions, I am fine with leaving it as it is.
If customers can use Express v5 with these ^ versions, then we an update the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I don't completely understand this.
Are you suggesting that we use the override here to use v4 or just leave it as it is (v5) ?

Copy link
Contributor

@kirrg001 kirrg001 Apr 1, 2025

Choose a reason for hiding this comment

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

As long as we still test against the right conditions, I am fine with leaving it as it is.

Conditions: The pinned production versions for the Otel exporter.

@kirrg001
Copy link
Contributor

kirrg001 commented Apr 1, 2025

@abhilash-sivan Please link the currency express ticket to Q2 currency epic. Thanks


beforeEach(async () => {
await agentControls.waitUntilAppIsCompletelyInitialized(expressControls.getPid());
['latest', 'v4'].forEach(version => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wrapped inside the version iterator and added version in application start calls


mochaSuiteFn('http with proxy', function () {
this.timeout(config.getTestTimeout());
['latest', 'v4'].forEach(version => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here also, only wrapped the tests in versions iterator and updated the server start commands with env variable

Copy link
Contributor

@kirrg001 kirrg001 left a comment

Choose a reason for hiding this comment

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

LGTM

@abhilash-sivan abhilash-sivan merged commit 8576291 into main Apr 1, 2025
1 check passed
@instanacd instanacd deleted the feat-add-express-v5 branch June 2, 2025 00:34
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.

4 participants