Skip to content

Commit 08f0157

Browse files
feat: upgrade to OpenTelemetry v2.x with cross-platform build support (Nodejs) (#50)
* feat: upgrade to OpenTelemetry v2.x with cross-platform build support - Update package.json to OpenTelemetry v2.x dependencies (47+ packages) - Fix TypeScript compilation errors with global.d.ts declarations - Add automatic architecture detection for arm64/amd64 builds - Update import paths for v2.x compatibility (otlp-proto → otlp-http) - Add webpack TypeScript configuration with test file exclusions - Add install-externals.sh for import-in-the-middle ESM instrumentation - Update opentelemetry-lambda submodule to commit 1fca858 (v2.x) Resolves build failures and enables cross-platform Lambda layer generation. Tested: make build-nodejs now builds successfully on arm64/amd64.
1 parent a54571a commit 08f0157

File tree

16 files changed

+357
-74
lines changed

16 files changed

+357
-74
lines changed

.github/workflows/publish-dev-layer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ jobs:
3333
aws_region: [ eu-central-1 ]
3434
env:
3535
LANGUAGE: ${{ inputs.LANGUAGE }}
36-
LAYER_NAME: ${{ github.head_ref }}-${{ inputs.LANGUAGE }}-${{ matrix.architecture }}
36+
LAYER_NAME: sumologic-otel-lambda-dev-${{ inputs.LANGUAGE }}-${{ matrix.architecture }}-${{ github.run_id }}
3737
ARCHITECTURE: ${{ matrix.architecture }}
3838
ARTIFACT_ARCHIVE_BASE_NAME: ${{ inputs.ARTIFACT_ARCHIVE_BASE_NAME }}
3939
ARTIFACT_NAME: ${{ inputs.ARTIFACT_NAME }}
40-
BUCKET_NAME: ${{ github.head_ref }}-${{ inputs.LANGUAGE }}-${{ matrix.architecture }}-${{ github.run_id }}
40+
BUCKET_NAME: sumologic-otel-lambda-dev-${{ github.run_id }}-${{ matrix.architecture }}
4141
BUCKET_KEY: layer-${{ matrix.architecture }}-${{ matrix.aws_region }}-.zip
4242
DIRECTORY: ${{ inputs.LANGUAGE }}
4343
REGION: ${{ matrix.aws_region }}

collector/build.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@
55
cp ./src/main.go ../opentelemetry-lambda/collector
66
cp ./src/internal/telemetryapi/listener.go ../opentelemetry-lambda/collector/internal/telemetryapi/listener.go
77

8+
# Detect architecture to use for building
9+
ARCH_TO_USE=$(./detect-arch.sh)
10+
811
# Build collector
912

1013
pushd ../opentelemetry-lambda/collector || exit
1114
make install-tools
1215
make gofmt
13-
make package
16+
make build
17+
# Package manually to fix config
18+
mkdir -p build/collector-config
19+
cp ../../collector/config/config.yaml build/collector-config/config.yaml
20+
cd build && zip -r opentelemetry-collector-layer-${ARCH_TO_USE}.zip collector-config extensions
1421
popd || exit
1522

1623
# Add config.yaml
1724

18-
cp ../opentelemetry-lambda/collector/build/opentelemetry-collector-layer-${GOARCH}.zip .
19-
unzip -qo opentelemetry-collector-layer-${GOARCH}.zip
20-
rm opentelemetry-collector-layer-${GOARCH}.zip
25+
cp ../opentelemetry-lambda/collector/build/opentelemetry-collector-layer-${ARCH_TO_USE}.zip .
26+
unzip -qo opentelemetry-collector-layer-${ARCH_TO_USE}.zip
27+
rm opentelemetry-collector-layer-${ARCH_TO_USE}.zip
2128
cp ./config/config.yaml ./collector-config/config.yaml
2229
zip -r collector-layer.zip collector-config extensions

collector/config/config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ receivers:
66

77
exporters:
88
otlphttp:
9-
endpoint: $SUMO_OTLP_HTTP_ENDPOINT_URL
9+
endpoint: ${env:SUMO_OTLP_HTTP_ENDPOINT_URL}
1010

1111
service:
1212
pipelines:
1313
traces:
1414
receivers: [otlp]
1515
exporters: [otlphttp]
16+
telemetry:
17+
logs:
18+
level: info
19+
metrics:
20+
level: none

collector/detect-arch.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Architecture detection script
4+
# Returns the architecture to use for building (amd64 or arm64)
5+
6+
# Use GOARCH (CI) or ARCHITECTURE (local) from environment, default to host architecture if not set
7+
if [ -n "$GOARCH" ]; then
8+
echo "$GOARCH"
9+
elif [ -n "$ARCHITECTURE" ]; then
10+
echo "$ARCHITECTURE"
11+
else
12+
HOST_ARCH=$(uname -m)
13+
case $HOST_ARCH in
14+
x86_64)
15+
echo "amd64"
16+
;;
17+
arm64|aarch64)
18+
echo "arm64"
19+
;;
20+
*)
21+
echo "Unsupported architecture: $HOST_ARCH" >&2
22+
exit 1
23+
;;
24+
esac
25+
fi

nodejs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Sumo Logic lambda layers support:
44

5-
- `nodejs16.x`, `nodejs18.x` and `nodejs20.x` runtimes
5+
- `nodejs18.x`, `nodejs20.x` and `nodejs22.x` runtimes
66
- `x86_64` and `arm64` architectures
77

88
## AMD64 Lambda Layers List

nodejs/build.sh

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,62 @@
11
#!/bin/bash
22

3+
# Detect or use provided architecture
4+
if [ -z "$ARCHITECTURE" ]; then
5+
# Auto-detect host architecture if ARCHITECTURE not set
6+
ARCH=$(uname -m)
7+
case $ARCH in
8+
x86_64)
9+
ARCHITECTURE="amd64"
10+
;;
11+
arm64|aarch64)
12+
ARCHITECTURE="arm64"
13+
;;
14+
*)
15+
echo "Unsupported architecture: $ARCH"
16+
exit 1
17+
;;
18+
esac
19+
echo "Auto-detected architecture: $ARCHITECTURE"
20+
else
21+
echo "Using provided architecture: $ARCHITECTURE"
22+
fi
23+
24+
# Export for use in collector build
25+
export ARCHITECTURE
26+
export GOARCH=$ARCHITECTURE
27+
328
# Build collector
429

530
pushd ../collector || exit
631
./build.sh
732
popd || exit
833

934
# Copy wrapper.ts
10-
1135
cp ./packages/layer/src/wrapper.ts ../opentelemetry-lambda/nodejs/packages/layer/src/wrapper.ts
1236

1337
# Copy package.json
14-
1538
cp ./packages/layer/package.json ../opentelemetry-lambda/nodejs/packages/layer/package.json
1639

17-
# Build nodejs sdk
40+
# Copy global.d.ts with type declarations
41+
cp ./packages/layer/src/global.d.ts ../opentelemetry-lambda/nodejs/packages/layer/src/global.d.ts
42+
43+
# Copy other necessary configuration files
44+
cp ./packages/layer/webpack.config.js ../opentelemetry-lambda/nodejs/packages/layer/webpack.config.js 2>/dev/null || true
45+
cp ./packages/layer/tsconfig.webpack.json ../opentelemetry-lambda/nodejs/packages/layer/tsconfig.webpack.json 2>/dev/null || true
46+
cp ./packages/layer/install-externals.sh ../opentelemetry-lambda/nodejs/packages/layer/install-externals.sh 2>/dev/null || true
47+
chmod +x ../opentelemetry-lambda/nodejs/packages/layer/install-externals.sh 2>/dev/null || true
1848

49+
# Build nodejs sdk and sample apps
1950
pushd ../opentelemetry-lambda/nodejs || exit
2051
npm install
52+
# Build all packages including sample apps with lerna
53+
npm run build
2154
popd || exit
2255

2356
# Combine collector extension with nodejs sdk
2457
## Copy and extract all files
2558
mkdir combine
26-
cp ../collector/collector-layer.zip ./combine
59+
cp ../collector/collector-layer.zip ./combine/collector-layer.zip
2760
cp ../opentelemetry-lambda/nodejs/packages/layer/build/layer.zip ./combine
2861

2962
unzip -qo combine/collector-layer.zip -d combine

nodejs/layer-data.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
OFFICIAL_LAYER_NAME=sumologic-otel-lambda-nodejs
44
ARCHITECTURE_AMD=x86_64
55
ARCHITECTURE_ARM=arm64
6-
RUNTIMES='nodejs16.x nodejs18.x nodejs20.x'
6+
RUNTIMES='nodejs18.x nodejs20.x nodejs22.x'
77
DESCRIPTION='Sumo Logic OTel Collector and NodeJS Lambda Layer https://github.com/SumoLogic/sumologic-otel-lambda/tree/main/nodejs'
88
LICENSE=Apache-2.0
9-
VERSION=v1-17-2
9+
VERSION=v2-0-0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -euf -o pipefail
4+
5+
rm -rf ./build/workspace/node_modules
6+
7+
# Space separated list of external NPM packages
8+
EXTERNAL_PACKAGES=( "import-in-the-middle" )
9+
10+
for EXTERNAL_PACKAGE in "${EXTERNAL_PACKAGES[@]}"
11+
do
12+
echo "Installing external package $EXTERNAL_PACKAGE ..."
13+
14+
PACKAGE_VERSION=$(npm query "#$EXTERNAL_PACKAGE" \
15+
| grep version \
16+
| head -1 \
17+
| awk -F: '{ print $2 }' \
18+
| sed 's/[",]//g')
19+
20+
echo "Resolved version of the external package $EXTERNAL_PACKAGE: $PACKAGE_VERSION"
21+
22+
npm install "$EXTERNAL_PACKAGE@$PACKAGE_VERSION" --prefix ./build/workspace --production --ignore-scripts
23+
24+
echo "Installed external package $EXTERNAL_PACKAGE"
25+
done

nodejs/packages/layer/package.json

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55
"description": "Layer including OpenTelemetry SDK for use with AWS Lambda.",
66
"repository": "open-telemetry/opentelemetry-lambda",
77
"scripts": {
8+
"build": "npm run clean && npm run compile && npm run install-externals && npm run package",
89
"clean": "rimraf build/*",
9-
"lint": "eslint . --ext .ts",
10-
"lint:fix": "eslint . --ext .ts --fix",
11-
"prepare": "npm run compile",
12-
"compile": "tsc -p .",
13-
"postcompile": "copyfiles 'node_modules/**' build/workspace/nodejs && copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*' build/workspace && cd build/workspace && bestzip ../layer.zip *"
10+
"compile:tsc": "tsc --build tsconfig.json",
11+
"compile:webpack": "webpack",
12+
"compile": "npm run compile:webpack",
13+
"copy-js-files": "copyfiles -f 'src/**/*.js' build/workspace && copyfiles 'test/**/*.js' build",
14+
"copy-esm-files": "copyfiles -f 'src/**/*.mjs' build/workspace && copyfiles 'test/**/*.mjs' build",
15+
"install-externals": "./install-externals.sh",
16+
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint . --ext .ts",
17+
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint . --ext .ts --fix",
18+
"package": "cd build/workspace && bestzip ../layer.zip *",
19+
"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",
20+
"pretest": "npm run compile:tsc",
21+
"test:cjs": "mocha 'test/**/*.spec.ts' --exclude 'test/**/*.spec.mjs' --timeout 10000",
22+
"test:esm": "mocha 'test/**/*.spec.mjs' --exclude 'test/**/*.spec.ts' --timeout 10000",
23+
"test": "npm run test:cjs && npm run test:esm"
1424
},
1525
"keywords": [
1626
"opentelemetry",
@@ -23,33 +33,69 @@
2333
"author": "OpenTelemetry Authors",
2434
"license": "Apache-2.0",
2535
"engines": {
26-
"node": ">=14.0.0"
36+
"node": ">=18.19.0"
2737
},
2838
"dependencies": {
29-
"@opentelemetry/api": "1.6.0",
30-
"@opentelemetry/exporter-trace-otlp-proto": "0.44.0",
31-
"@opentelemetry/exporter-metrics-otlp-proto": "0.44.0",
32-
"@opentelemetry/instrumentation": "0.44.0",
33-
"@opentelemetry/instrumentation-aws-lambda": "0.37.1",
34-
"@opentelemetry/instrumentation-aws-sdk": "0.36.1",
35-
"@opentelemetry/instrumentation-dns": "0.32.3",
36-
"@opentelemetry/instrumentation-express": "0.33.2",
37-
"@opentelemetry/instrumentation-graphql": "0.35.2",
38-
"@opentelemetry/instrumentation-grpc": "0.44.0",
39-
"@opentelemetry/instrumentation-hapi": "0.33.1",
40-
"@opentelemetry/instrumentation-http": "0.44.0",
41-
"@opentelemetry/instrumentation-ioredis": "0.35.2",
42-
"@opentelemetry/instrumentation-koa": "0.36.1",
43-
"@opentelemetry/instrumentation-mongodb": "0.37.1",
44-
"@opentelemetry/instrumentation-mysql": "0.34.2",
45-
"@opentelemetry/instrumentation-net": "0.32.2",
46-
"@opentelemetry/instrumentation-pg": "0.36.2",
47-
"@opentelemetry/instrumentation-redis": "0.35.2",
48-
"@opentelemetry/propagator-aws-xray": "1.3.0",
49-
"@opentelemetry/resource-detector-aws": "1.3.2",
50-
"@opentelemetry/resources": "1.17.1",
51-
"@opentelemetry/sdk-metrics": "1.17.1",
52-
"@opentelemetry/sdk-trace-base": "1.17.1",
53-
"@opentelemetry/sdk-trace-node": "1.17.1"
54-
}
39+
"@opentelemetry/api": "^1.9.0",
40+
"@opentelemetry/api-logs": "^0.203.0",
41+
"@opentelemetry/core": "^2.0.0",
42+
"@opentelemetry/exporter-logs-otlp-http": "^0.203.0",
43+
"@opentelemetry/exporter-metrics-otlp-http": "^0.203.0",
44+
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
45+
"@opentelemetry/instrumentation": "^0.203.0",
46+
"@opentelemetry/instrumentation-amqplib": "^0.50.0",
47+
"@opentelemetry/instrumentation-aws-lambda": "^0.54.0",
48+
"@opentelemetry/instrumentation-aws-sdk": "^0.56.0",
49+
"@opentelemetry/instrumentation-bunyan": "^0.49.0",
50+
"@opentelemetry/instrumentation-cassandra-driver": "^0.49.0",
51+
"@opentelemetry/instrumentation-connect": "^0.47.0",
52+
"@opentelemetry/instrumentation-dataloader": "^0.21.0",
53+
"@opentelemetry/instrumentation-dns": "^0.47.0",
54+
"@opentelemetry/instrumentation-express": "^0.52.0",
55+
"@opentelemetry/instrumentation-fs": "^0.23.0",
56+
"@opentelemetry/instrumentation-graphql": "^0.51.0",
57+
"@opentelemetry/instrumentation-grpc": "^0.203.0",
58+
"@opentelemetry/instrumentation-hapi": "^0.50.0",
59+
"@opentelemetry/instrumentation-http": "^0.203.0",
60+
"@opentelemetry/instrumentation-ioredis": "^0.51.0",
61+
"@opentelemetry/instrumentation-kafkajs": "^0.12.0",
62+
"@opentelemetry/instrumentation-knex": "^0.48.0",
63+
"@opentelemetry/instrumentation-koa": "^0.51.0",
64+
"@opentelemetry/instrumentation-memcached": "^0.47.0",
65+
"@opentelemetry/instrumentation-mongodb": "^0.56.0",
66+
"@opentelemetry/instrumentation-mongoose": "^0.50.0",
67+
"@opentelemetry/instrumentation-mysql": "^0.49.0",
68+
"@opentelemetry/instrumentation-mysql2": "^0.49.0",
69+
"@opentelemetry/instrumentation-nestjs-core": "^0.49.0",
70+
"@opentelemetry/instrumentation-net": "^0.47.0",
71+
"@opentelemetry/instrumentation-pg": "^0.55.0",
72+
"@opentelemetry/instrumentation-pino": "^0.50.0",
73+
"@opentelemetry/instrumentation-redis": "^0.51.0",
74+
"@opentelemetry/instrumentation-restify": "^0.49.0",
75+
"@opentelemetry/instrumentation-socket.io": "^0.50.0",
76+
"@opentelemetry/instrumentation-undici": "^0.14.0",
77+
"@opentelemetry/instrumentation-winston": "^0.48.0",
78+
"@opentelemetry/propagator-aws-xray": "^2.0.0",
79+
"@opentelemetry/propagator-aws-xray-lambda": "^0.55.0",
80+
"@opentelemetry/resource-detector-aws": "^2.0.0",
81+
"@opentelemetry/resources": "^2.0.0",
82+
"@opentelemetry/sdk-logs": "^0.203.0",
83+
"@opentelemetry/sdk-metrics": "^2.0.0",
84+
"@opentelemetry/sdk-trace-node": "^2.0.0"
85+
},
86+
"devDependencies": {
87+
"@types/mocha": "^10.0.9",
88+
"@types/sinon": "^17.0.4",
89+
"bestzip": "^2.2.1",
90+
"copyfiles": "^2.4.1",
91+
"mocha": "^11.0.1",
92+
"rimraf": "^6.0.1",
93+
"sinon": "^21.0.0",
94+
"ts-loader": "^9.5.2",
95+
"ts-node": "^10.9.2",
96+
"webpack": "^5.98.0",
97+
"webpack-cli": "^6.0.1",
98+
"webpack-node-externals": "^3.0.0"
99+
},
100+
"sideEffects": false
55101
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# - Use Instrumentation
4+
5+
export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"
6+
7+
# - Set the service name
8+
9+
if [[ -z "${OTEL_SERVICE_NAME}" ]]; then
10+
export OTEL_SERVICE_NAME=${AWS_LAMBDA_FUNCTION_NAME};
11+
fi
12+
13+
# - Set Lambda specific resource attributes
14+
15+
export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=${AWS_REGION},cloud.provider=aws,faas.name=${AWS_LAMBDA_FUNCTION_NAME},faas.version=${AWS_LAMBDA_FUNCTION_VERSION}";
16+
17+
if [[ -z "${OTEL_RESOURCE_ATTRIBUTES}" ]]; then
18+
export OTEL_RESOURCE_ATTRIBUTES=${LAMBDA_RESOURCE_ATTRIBUTES};
19+
else
20+
export OTEL_RESOURCE_ATTRIBUTES="${LAMBDA_RESOURCE_ATTRIBUTES},${OTEL_RESOURCE_ATTRIBUTES}";
21+
fi
22+
23+
exec "$@"

0 commit comments

Comments
 (0)