Skip to content

test: added esbuild example #1713

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

Merged
merged 9 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/collector/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ test/apps/babel-typescript/
test/metrics/app/node_modules/
test/metrics/npmInstalledApp/node_modules/
test/tracing/frameworks/tsoa/build/
test/tracing/misc/typescript/
test/tracing/misc/typescript/
test/tracing/misc/esbuild-external/dist
6 changes: 4 additions & 2 deletions packages/collector/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ test/bin/edgemicroResources/cli/edgemicro
test/tracing/database/prisma/package.json
test/tracing/database/prisma/package-lock.json


test/tracing/misc/typescript/ts_esm/dist
test/tracing/misc/typescript/ts_cjs/dist
test/tracing/misc/typescript/ts_cjs/dist

test/tracing/misc/esbuild-external/dist/
test/tracing/misc/esbuild-external/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

INSTANA_ENDPOINT=
INSTANA_AGENT_KEY=
16 changes: 16 additions & 0 deletions packages/collector/test/tracing/misc/esbuild-external/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Notes

For `esbuild` you MUST define the NPM production dependencies in the `external` configuration, otherwise `esbuild` will bundle **all** production dependencies into
one dist file and it will no longer use `require` or `import`, because the code
is accessible in the dist file itself.

# Build

```sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Qs: why this sample app is placed here? I’m wondering if I might be missing a corresponding test 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.

Where do you want to put it elsewise?
We can later connect it with a test if we want, but the effort is too high right now.
This esbuild folder is code knowledge sharing

Copy link
Contributor

Choose a reason for hiding this comment

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

The packages/collector/test/tracing normally contains integration tests. Would it be more appropriate to place this in the example-apps instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm IMO misc is the right place (we have all kinds of build pipeline examples in here), but I agree with you too that it also could be moved to examples. But IMO its a bit too small and too special for examples.

npm i
cp .env.template .env
npm run build
npm run package
```

Optionally, upload `dist/instana-test-esbuild-0.17.19.vsix` to VSCode and run the command "Run Instana Axios Demo".
29 changes: 29 additions & 0 deletions packages/collector/test/tracing/misc/esbuild-external/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import esbuild from 'esbuild';
import pkg from './package.json' assert { type: 'json' };

async function build() {
/** @type {esbuild.BuildOptions} */
const options = {
entryPoints: ['./extension.ts'],
outfile: `./dist/extension.js`,
bundle: true,
format: 'cjs',
platform: 'node',
minify: false,
define: {
'process.env.NODE_OPTIONS': JSON.stringify('--require ./node_modules/@instana/serverless-collector/src/index.js'),
'process.env.INSTANA_ENDPOINT': JSON.stringify(process.env.INSTANA_ENDPOINT),
'process.env.INSTANA_AGENT_KEY': JSON.stringify(process.env.INSTANA_AGENT_KEY)
},
sourcemap: 'inline',
sourcesContent: false,
external: ['vscode', ...Object.keys(pkg.dependencies)]
};

await esbuild.build(options);
}

build().catch(err => {
console.error(err);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as vscode from 'vscode';
import { runInstanaJob } from './server';

export function activate(context: vscode.ExtensionContext) {
console.log('Extension "instana-axios-demo" is now active!');

const disposable = vscode.commands.registerCommand('instanaAxiosDemo.run', async () => {
vscode.window.showInformationMessage('Running Instana Axios Job...');
vscode.window.showInformationMessage(process.env.NODE_OPTIONS);
vscode.window.showInformationMessage(process.env.INSTANA_ENDPOINT);
await runInstanaJob();
});

context.subscriptions.push(disposable);
}

export function deactivate() {
console.log('Extension "instana-axios-demo" is now deactivated.');
}
Loading