Skip to content

Commit 475135f

Browse files
[nodejs] Aligns development and CI flows to avoid issues (#67)
Fixes ES-492. This PR aligns the development an CI flows when it comes to where they expect the forked dependencies to be. If they are in different places between development and CI flows, there might be some issues with the CI build. This happens because even though the forked libraries might be put wherever we want at development time, in the CI they are expected to be inside the root folder of the repository because of limitations in the CI runners. The problem starts because the location of the libraries during development will influence the contents of the `package.json` files, which will be wrong from the perspective of the CI. **tl;dr:** all the forked repos have to be cloned **inside** the root folder of this repository. This should **not** be changed. Additionally the following was done: - Forked libraries added to `.gitignore`. - `.envrc` (auto env-var loader) added to `.gitignore`. - `mise.toml` (polyglot version manager configuration file) added to `.gitignore`. - CI runner now uses the `setup-nodejs` action. - CI runner nodejs was upgraded to version 20 to clear up CI warnings at build time. - CI runner OS upgraded to Ubuntu 24.04. - The layer build script runs an `npm cache clean --force` before doing anything to ensure a clean starting state. - The README has been updated with better development instructions according to recent changes and experiences. - `opentelemetry-propagator-aws-xray` and `opentelemetry-propagator-aws-xray-lambda` are manually compiled, as they are new dependencies of `opentelemetry-instrumentation-aws-lambda`.
1 parent 35c3ccd commit 475135f

10 files changed

Lines changed: 615 additions & 1017 deletions

File tree

.github/workflows/publish-nodejs.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
jobs:
1313

1414
package:
15-
runs-on: ubuntu-22.04
15+
runs-on: ubuntu-24.04
1616
if: ${{ github.ref == 'refs/heads/coralogix-nodejs-autoinstrumentation' || inputs.environment == 'test' }}
1717
environment: ${{ inputs.environment }}
1818
env:
@@ -39,6 +39,9 @@ jobs:
3939
repository: coralogix/import-in-the-middle
4040
ref: refs/heads/coralogix-autoinstrumentation
4141
ssh-key: ${{ secrets.OPENTELEMETRY_CI_IITM_GITHUB_KEY }}
42+
- uses: actions/setup-node@v4
43+
with:
44+
node-version: 20
4245
- name: Build
4346
run: ./ci-scripts/build_nodejs_layer.sh
4447
- name: Check layer size
@@ -102,4 +105,4 @@ jobs:
102105
env:
103106
LAYER_NAME: "coralogix-opentelemetry-nodejs-wrapper"
104107
COMPATIBLE_RUNTIMES: "nodejs16.x nodejs18.x nodejs20.x"
105-
run: ./ci-scripts/publish_${{ inputs.environment }}.sh
108+
run: ./ci-scripts/publish_${{ inputs.environment }}.sh

.github/workflows/release-layer-nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- uses: actions/setup-node@v4
2222
with:
23-
node-version: 18
23+
node-version: 20
2424

2525
- name: Build
2626
run: |

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ build.toml
2222
tsconfig.tsbuildinfo
2323

2424
collector/VERSION
25+
26+
opentelemetry-js/
27+
opentelemetry-js-contrib-cx/
28+
import-in-the-middle/
29+
30+
.envrc
31+
mise.toml

ci-scripts/build_nodejs_layer.sh

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ echo "OPENTELEMETRY_JS_PATH=$OPENTELEMETRY_JS_PATH"
2727
echo "IITM_PATH=$IITM_PATH"
2828
echo "CWD=$CWD"
2929

30+
npm cache clean --force
31+
3032
pushd "$OPENTELEMETRY_JS_CONTRIB_PATH" > /dev/null
3133
# Generate version files in opentelemetry-js-contrib
3234
npx lerna@6.6.2 run version:update # Newer versions have trouble with our lerna.json which contains `useWorkspaces`
@@ -40,9 +42,14 @@ npm install && npm run compile
4042
popd > /dev/null
4143

4244
# Build opentelemetry-propagator-aws-xray
43-
# pushd $OPENTELEMETRY_JS_CONTRIB_PATH/propagators/opentelemetry-propagator-aws-xray
44-
# npm install && npm run compile
45-
# popd > /dev/null
45+
pushd "$OPENTELEMETRY_JS_CONTRIB_PATH/propagators/propagator-aws-xray" > /dev/null
46+
npm install --ignore-scripts && npm run compile
47+
popd > /dev/null
48+
49+
# Build opentelemetry-propagator-aws-xray-lambda
50+
pushd "$OPENTELEMETRY_JS_CONTRIB_PATH/propagators/propagator-aws-xray-lambda" > /dev/null
51+
npm install && npm run compile
52+
popd > /dev/null
4653

4754
# Build opentelemetry-propagation-utils
4855
pushd "$OPENTELEMETRY_JS_CONTRIB_PATH/packages/opentelemetry-propagation-utils" > /dev/null
@@ -81,6 +88,7 @@ popd > /dev/null
8188
pushd "$OPENTELEMETRY_JS_PATH/experimental/packages/opentelemetry-instrumentation" > /dev/null
8289
rm -f opentelemetry-instrumentation-*.tgz
8390
npm install && npm run compile && npm pack
91+
ls -lah opentelemetry-instrumentation-*.tgz
8492
popd > /dev/null
8593

8694
# Build opentelemetry-sdk-trace-base
@@ -98,11 +106,11 @@ popd > /dev/null
98106
# Install forked libraries in cx-wrapper
99107
pushd "./nodejs/packages/cx-wrapper" > /dev/null
100108
npm install \
101-
"${OPENTELEMETRY_JS_CONTRIB_PATH}/plugins/node/opentelemetry-instrumentation-aws-lambda/opentelemetry-instrumentation-aws-lambda-"*.tgz \
102-
"${OPENTELEMETRY_JS_CONTRIB_PATH}/plugins/node/opentelemetry-instrumentation-mongodb/opentelemetry-instrumentation-mongodb-"*.tgz \
103-
"${OPENTELEMETRY_JS_CONTRIB_PATH}/plugins/node/opentelemetry-instrumentation-aws-sdk/opentelemetry-instrumentation-aws-sdk-"*.tgz \
104-
"${OPENTELEMETRY_JS_PATH}/experimental/packages/opentelemetry-instrumentation/opentelemetry-instrumentation-"*.tgz \
105-
"${IITM_PATH}/import-in-the-middle-"*.tgz
109+
"${OPENTELEMETRY_JS_CONTRIB_PATH}"/plugins/node/opentelemetry-instrumentation-aws-lambda/opentelemetry-instrumentation-aws-lambda-*.tgz \
110+
"${OPENTELEMETRY_JS_CONTRIB_PATH}"/plugins/node/opentelemetry-instrumentation-mongodb/opentelemetry-instrumentation-mongodb-*.tgz \
111+
"${OPENTELEMETRY_JS_CONTRIB_PATH}"/plugins/node/opentelemetry-instrumentation-aws-sdk/opentelemetry-instrumentation-aws-sdk-*.tgz \
112+
"${OPENTELEMETRY_JS_PATH}"/experimental/packages/opentelemetry-instrumentation/opentelemetry-instrumentation-*.tgz \
113+
"${IITM_PATH}"/import-in-the-middle-*.tgz
106114
popd > /dev/null
107115

108116
# Build cx-wrapper
@@ -114,12 +122,12 @@ popd > /dev/null
114122
# Install libraries in layer
115123
pushd "./nodejs/packages/layer" > /dev/null
116124
npm install \
117-
"${OPENTELEMETRY_JS_CONTRIB_PATH}/plugins/node/opentelemetry-instrumentation-aws-lambda/opentelemetry-instrumentation-aws-lambda-"*.tgz \
118-
"${OPENTELEMETRY_JS_CONTRIB_PATH}/plugins/node/opentelemetry-instrumentation-mongodb/opentelemetry-instrumentation-mongodb-"*.tgz \
119-
"${OPENTELEMETRY_JS_CONTRIB_PATH}/plugins/node/opentelemetry-instrumentation-aws-sdk/opentelemetry-instrumentation-aws-sdk-"*.tgz \
120-
"${OPENTELEMETRY_JS_PATH}/experimental/packages/opentelemetry-instrumentation/opentelemetry-instrumentation-"*.tgz \
121-
"${IITM_PATH}/import-in-the-middle-"*.tgz \
122-
"${CWD}/nodejs/packages/cx-wrapper/cx-wrapper-"*.tgz
125+
"${OPENTELEMETRY_JS_CONTRIB_PATH}"/plugins/node/opentelemetry-instrumentation-aws-lambda/opentelemetry-instrumentation-aws-lambda-*.tgz \
126+
"${OPENTELEMETRY_JS_CONTRIB_PATH}"/plugins/node/opentelemetry-instrumentation-mongodb/opentelemetry-instrumentation-mongodb-*.tgz \
127+
"${OPENTELEMETRY_JS_CONTRIB_PATH}"/plugins/node/opentelemetry-instrumentation-aws-sdk/opentelemetry-instrumentation-aws-sdk-*.tgz \
128+
"${OPENTELEMETRY_JS_PATH}"/experimental/packages/opentelemetry-instrumentation/opentelemetry-instrumentation-*.tgz \
129+
"${IITM_PATH}"/import-in-the-middle-*.tgz \
130+
"${CWD}"/nodejs/packages/cx-wrapper/cx-wrapper-*.tgz
123131
popd > /dev/null
124132

125133
# Install copyfiles and bestzip # used by `npm run clean/compile`
@@ -128,4 +136,5 @@ npm install -g copyfiles bestzip rimraf
128136
# Build layer
129137
pushd "./nodejs/packages/layer" > /dev/null
130138
npm run clean && npm install
131-
popd > /dev/null
139+
ls -lah build/layer.zip
140+
popd > /dev/null

dev/build-nodejs.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ ROOT_DIR=$(git rev-parse --show-toplevel)
1010

1111
# Expected by build_nodejs_layer.sh
1212
if [ -z "$OPENTELEMETRY_JS_CONTRIB_PATH" ]; then
13-
export OPENTELEMETRY_JS_CONTRIB_PATH="$ROOT_DIR/../opentelemetry-js-contrib-cx"
13+
export OPENTELEMETRY_JS_CONTRIB_PATH="$ROOT_DIR/opentelemetry-js-contrib-cx"
1414
fi
1515

1616
if [ -z "$OPENTELEMETRY_JS_PATH" ]; then
17-
export OPENTELEMETRY_JS_PATH="$ROOT_DIR/../oss/opentelemetry-js"
17+
export OPENTELEMETRY_JS_PATH="$ROOT_DIR/opentelemetry-js"
1818
fi
1919

2020
if [ -z "$IITM_PATH" ]; then
21-
export IITM_PATH="$ROOT_DIR/../import-in-the-middle"
21+
export IITM_PATH="$ROOT_DIR/import-in-the-middle"
2222
fi
2323

2424
if [ ! -d "$OPENTELEMETRY_JS_CONTRIB_PATH" ]; then
25-
git clone git@github.com:coralogix/opentelemetry-js-contrib.git "$OPENTELEMETRY_JS_CONTRIB_PATH" -b coralogix-autoinstrumentation
25+
git clone git@github.com:coralogix/opentelemetry-js-contrib.git "$OPENTELEMETRY_JS_CONTRIB_PATH" -b coralogix-autoinstrumentation
2626
fi
2727

2828
if [ ! -d "$OPENTELEMETRY_JS_PATH" ]; then
29-
git clone git@github.com:coralogix/opentelemetry-js.git "$OPENTELEMETRY_JS_PATH" -b coralogix-autoinstrumentation
29+
git clone git@github.com:coralogix/opentelemetry-js.git "$OPENTELEMETRY_JS_PATH" -b coralogix-autoinstrumentation
3030
fi
3131

3232
if [ ! -d "$IITM_PATH" ]; then
33-
git clone git@github.com:coralogix/import-in-the-middle.git "$IITM_PATH" -b coralogix-autoinstrumentation
33+
git clone git@github.com:coralogix/import-in-the-middle.git "$IITM_PATH" -b coralogix-autoinstrumentation
3434
fi
3535

3636
"$ROOT_DIR/ci-scripts/build_nodejs_layer.sh"
3737

3838
# Useful for using the layer locally
39-
pushd "$ROOT_DIR/nodejs/packages/layer" > /dev/null
39+
pushd "$ROOT_DIR/nodejs/packages/layer" >/dev/null
4040
rm -rf ./build/layer && unzip -q ./build/layer.zip -d ./build/layer
41-
popd > /dev/null
41+
popd >/dev/null

nodejs/README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,49 @@ included and loaded automatically if you use the AWS SDK v2.
1010

1111
## Building
1212

13-
To build the layer and sample applications, in this `nodejs` folder, run
13+
### Requirements
1414

15+
You will need to provide the path to 3 forked dependencies through environment
16+
variables for the libraries below:
17+
18+
- opentelemetry-js: `OPENTELEMETRY_JS_PATH`.
19+
- opentelemetry-js-contrib: `OPENTELEMETRY_JS_CONTRIB_PATH`.
20+
- import-in-the-middle: `IITM_PATH`.
21+
22+
Note that these paths are very important, because they are will impact the
23+
relative paths in some `package.json` files in ways that could potentially
24+
break CI scripts.
25+
26+
To avoid this issue we recommend setting them like so:
27+
28+
```sh
29+
export OPENTELEMETRY_JS_CONTRIB_PATH=./opentelemetry-js-contrib-cx
30+
export OPENTELEMETRY_JS_PATH=./opentelemetry-js
31+
export IITM_PATH=./import-in-the-middle
1532
```
16-
npm install
33+
34+
This project's `.gitignore` is already configured with these folders
35+
to ensure your git index stays clean.
36+
37+
### The layer
38+
39+
To build the layer and sample applications run the command below from
40+
the root of the application:
41+
42+
```sh
43+
./dev/build-nodejs.sh
1744
```
1845

19-
This will download all dependencies and compile all code. The layer zip file will be present at `./packages/layer/build/layer.zip`.
46+
This is a thin wrapper over `./ci-scripts/build_nodejs_layer.sh` that
47+
will clone the forked dependencies if the paths indicated by the
48+
previously mentioned environment variables are empty, then use
49+
that script to download all dependencies and compile all code.
50+
The layer zip file will be present at `./packages/layer/build/layer.zip`.
2051

2152
## Sample applications
2253

2354
Sample applications are provided to show usage of the above layer.
2455

2556
- Application using AWS SDK - shows using the wrapper with an application using AWS SDK without code change.
2657
- [Using layer built from source](./integration-tests/aws-sdk)
27-
- [WIP] [Using OTel Public Layer](./sample-apps/aws-sdk)
58+
- [WIP] [Using OTel Public Layer](./sample-apps/aws-sdk)

0 commit comments

Comments
 (0)