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(nodejs): bundling with webpack #1679

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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,610 changes: 2,456 additions & 1,154 deletions nodejs/package-lock.json

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions nodejs/packages/layer/install-externals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -euf -o pipefail

rm -rf ./build/workspace/node_modules

# Space separated list of external NPM packages
EXTERNAL_PACKAGES=( "import-in-the-middle" )

for EXTERNAL_PACKAGE in "${EXTERNAL_PACKAGES[@]}"
do
echo "Installing external package $EXTERNAL_PACKAGE ..."

PACKAGE_VERSION=$(npm query "#$EXTERNAL_PACKAGE" \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')

echo "Resolved version of the external package $EXTERNAL_PACKAGE: $PACKAGE_VERSION"

npm install "$EXTERNAL_PACKAGE@$PACKAGE_VERSION" --prefix ./build/workspace --production --ignore-scripts

echo "Installed external package $EXTERNAL_PACKAGE"
done
1,339 changes: 1,299 additions & 40 deletions nodejs/packages/layer/package-lock.json

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions nodejs/packages/layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
"description": "Layer including OpenTelemetry SDK for use with AWS Lambda.",
"repository": "open-telemetry/opentelemetry-lambda",
"scripts": {
"build": "npm run clean && npm run compile && npm run install-externals && npm run package",
"clean": "rimraf build/*",
"compile:tsc": "tsc --build tsconfig.json",
"compile:webpack": "webpack",
"compile": "npm run compile:webpack",
"copy-js-files": "copyfiles -f 'src/**/*.js' build/workspace && copyfiles 'test/**/*.js' build",
"copy-esm-files": "copyfiles -f 'src/**/*.mjs' build/workspace && copyfiles 'test/**/*.mjs' build",
"install-externals": "./install-externals.sh",
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint . --ext .ts",
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint . --ext .ts --fix",
"build": "npm run clean && npm run compile && npm run postcompile",
"copy-esm-files": "copyfiles 'src/**/*.mjs' build && copyfiles 'test/**/*.mjs' build",
"compile": "tsc -p .",
"postcompile": "npm run copy-esm-files && copyfiles 'package*.json' build/workspace/nodejs && npm install --production --ignore-scripts --prefix build/workspace/nodejs && rm build/workspace/nodejs/package.json build/workspace/nodejs/package-lock.json && copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*' build/workspace && cd build/workspace && bestzip ../layer.zip *",
"pretest": "npm run compile",
"package": "cd build/workspace && bestzip ../layer.zip *",
"postcompile": "npm run copy-js-files && npm run copy-esm-files && copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*.js' build/workspace && copyfiles -f 'build/src/*.mjs' build/workspace",
"pretest": "npm run compile:tsc",
"test:cjs": "mocha 'test/**/*.spec.ts' --exclude 'test/**/*.spec.mjs' --timeout 10000",
"test:esm": "mocha 'test/**/*.spec.mjs' --exclude 'test/**/*.spec.ts' --timeout 10000",
"test": "npm run test:cjs && npm run test:esm"
Expand Down Expand Up @@ -67,6 +72,11 @@
"@types/sinon": "^17.0.3",
"mocha": "^11.0.1",
"sinon": "^19.0.2",
"ts-node": "^10.9.2"
}
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1",
"webpack-node-externals": "^3.0.0"
},
"sideEffects": false
}
2 changes: 1 addition & 1 deletion nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -ef -o pipefail

export NODE_OPTIONS="${NODE_OPTIONS} --import /opt/loader.mjs --require /opt/wrapper.js"
export NODE_OPTIONS="${NODE_OPTIONS} --import /opt/init.mjs"

if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
Expand Down
9 changes: 9 additions & 0 deletions nodejs/packages/layer/src/init.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const WRAPPER_INIT_START_TIME = Date.now();
const { default: wrapper } = await import('./wrapper.js');
await wrapper.init();
await wrapper.wrap();
console.log('OpenTelemetry wrapper init completed in', Date.now() - WRAPPER_INIT_START_TIME, 'ms');

const LOADER_INIT_START_TIME = Date.now();
await import('./loader.mjs');
console.log('OpenTelemetry loader init completed in', Date.now() - LOADER_INIT_START_TIME, 'ms');
Loading
Loading