Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions .github/workflows/publish-dev-layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
aws_region: [ eu-central-1 ]
env:
LANGUAGE: ${{ inputs.LANGUAGE }}
LAYER_NAME: ${{ github.head_ref }}-${{ inputs.LANGUAGE }}-${{ matrix.architecture }}
LAYER_NAME: sumologic-otel-lambda-dev-${{ inputs.LANGUAGE }}-${{ matrix.architecture }}-${{ github.run_id }}
ARCHITECTURE: ${{ matrix.architecture }}
ARTIFACT_ARCHIVE_BASE_NAME: ${{ inputs.ARTIFACT_ARCHIVE_BASE_NAME }}
ARTIFACT_NAME: ${{ inputs.ARTIFACT_NAME }}
BUCKET_NAME: ${{ github.head_ref }}-${{ inputs.LANGUAGE }}-${{ matrix.architecture }}-${{ github.run_id }}
BUCKET_NAME: sumologic-otel-lambda-dev-${{ github.run_id }}-${{ matrix.architecture }}
BUCKET_KEY: layer-${{ matrix.architecture }}-${{ matrix.aws_region }}-.zip
DIRECTORY: ${{ inputs.LANGUAGE }}
REGION: ${{ matrix.aws_region }}
Expand Down
15 changes: 11 additions & 4 deletions collector/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@
cp ./src/main.go ../opentelemetry-lambda/collector
cp ./src/internal/telemetryapi/listener.go ../opentelemetry-lambda/collector/internal/telemetryapi/listener.go

# Detect architecture to use for building
ARCH_TO_USE=$(./detect-arch.sh)

# Build collector

pushd ../opentelemetry-lambda/collector || exit
make install-tools
make gofmt
make package
make build
# Package manually to fix config
mkdir -p build/collector-config
cp ../../collector/config/config.yaml build/collector-config/config.yaml
cd build && zip -r opentelemetry-collector-layer-${ARCH_TO_USE}.zip collector-config extensions
popd || exit

# Add config.yaml

cp ../opentelemetry-lambda/collector/build/opentelemetry-collector-layer-${GOARCH}.zip .
unzip -qo opentelemetry-collector-layer-${GOARCH}.zip
rm opentelemetry-collector-layer-${GOARCH}.zip
cp ../opentelemetry-lambda/collector/build/opentelemetry-collector-layer-${ARCH_TO_USE}.zip .
unzip -qo opentelemetry-collector-layer-${ARCH_TO_USE}.zip
rm opentelemetry-collector-layer-${ARCH_TO_USE}.zip
cp ./config/config.yaml ./collector-config/config.yaml
zip -r collector-layer.zip collector-config extensions
7 changes: 6 additions & 1 deletion collector/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ receivers:

exporters:
otlphttp:
endpoint: $SUMO_OTLP_HTTP_ENDPOINT_URL
endpoint: ${env:SUMO_OTLP_HTTP_ENDPOINT_URL}

service:
pipelines:
traces:
receivers: [otlp]
exporters: [otlphttp]
telemetry:
logs:
level: info
metrics:
level: none
25 changes: 25 additions & 0 deletions collector/detect-arch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Architecture detection script
# Returns the architecture to use for building (amd64 or arm64)

# Use GOARCH (CI) or ARCHITECTURE (local) from environment, default to host architecture if not set
if [ -n "$GOARCH" ]; then
echo "$GOARCH"
elif [ -n "$ARCHITECTURE" ]; then
echo "$ARCHITECTURE"
else
HOST_ARCH=$(uname -m)
case $HOST_ARCH in
x86_64)
echo "amd64"
;;
arm64|aarch64)
echo "arm64"
;;
*)
echo "Unsupported architecture: $HOST_ARCH" >&2
exit 1
;;
esac
fi
2 changes: 1 addition & 1 deletion nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Sumo Logic lambda layers support:

- `nodejs16.x`, `nodejs18.x` and `nodejs20.x` runtimes
- `nodejs18.x`, `nodejs20.x` and `nodejs22.x` runtimes
- `x86_64` and `arm64` architectures

## AMD64 Lambda Layers List
Expand Down
41 changes: 37 additions & 4 deletions nodejs/build.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
#!/bin/bash

# Detect or use provided architecture
if [ -z "$ARCHITECTURE" ]; then
# Auto-detect host architecture if ARCHITECTURE not set
ARCH=$(uname -m)
case $ARCH in
x86_64)
ARCHITECTURE="amd64"
;;
arm64|aarch64)
ARCHITECTURE="arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
echo "Auto-detected architecture: $ARCHITECTURE"
else
echo "Using provided architecture: $ARCHITECTURE"
fi

# Export for use in collector build
export ARCHITECTURE
export GOARCH=$ARCHITECTURE

# Build collector

pushd ../collector || exit
./build.sh
popd || exit

# Copy wrapper.ts

cp ./packages/layer/src/wrapper.ts ../opentelemetry-lambda/nodejs/packages/layer/src/wrapper.ts

# Copy package.json

cp ./packages/layer/package.json ../opentelemetry-lambda/nodejs/packages/layer/package.json

# Build nodejs sdk
# Copy global.d.ts with type declarations
cp ./packages/layer/src/global.d.ts ../opentelemetry-lambda/nodejs/packages/layer/src/global.d.ts

# Copy other necessary configuration files
cp ./packages/layer/webpack.config.js ../opentelemetry-lambda/nodejs/packages/layer/webpack.config.js 2>/dev/null || true
cp ./packages/layer/tsconfig.webpack.json ../opentelemetry-lambda/nodejs/packages/layer/tsconfig.webpack.json 2>/dev/null || true
cp ./packages/layer/install-externals.sh ../opentelemetry-lambda/nodejs/packages/layer/install-externals.sh 2>/dev/null || true
chmod +x ../opentelemetry-lambda/nodejs/packages/layer/install-externals.sh 2>/dev/null || true

# Build nodejs sdk and sample apps
pushd ../opentelemetry-lambda/nodejs || exit
npm install
# Build all packages including sample apps with lerna
npm run build
popd || exit

# Combine collector extension with nodejs sdk
## Copy and extract all files
mkdir combine
cp ../collector/collector-layer.zip ./combine
cp ../collector/collector-layer.zip ./combine/collector-layer.zip
cp ../opentelemetry-lambda/nodejs/packages/layer/build/layer.zip ./combine

unzip -qo combine/collector-layer.zip -d combine
Expand Down
4 changes: 2 additions & 2 deletions nodejs/layer-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
OFFICIAL_LAYER_NAME=sumologic-otel-lambda-nodejs
ARCHITECTURE_AMD=x86_64
ARCHITECTURE_ARM=arm64
RUNTIMES='nodejs16.x nodejs18.x nodejs20.x'
RUNTIMES='nodejs18.x nodejs20.x nodejs22.x'
DESCRIPTION='Sumo Logic OTel Collector and NodeJS Lambda Layer https://github.com/SumoLogic/sumologic-otel-lambda/tree/main/nodejs'
LICENSE=Apache-2.0
VERSION=v1-17-2
VERSION=v2-0-0
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
110 changes: 78 additions & 32 deletions nodejs/packages/layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
"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/*",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prepare": "npm run compile",
"compile": "tsc -p .",
"postcompile": "copyfiles 'node_modules/**' build/workspace/nodejs && copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*' build/workspace && cd build/workspace && bestzip ../layer.zip *"
"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",
"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"
},
"keywords": [
"opentelemetry",
Expand All @@ -23,33 +33,69 @@
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"engines": {
"node": ">=14.0.0"
"node": ">=18.19.0"
},
"dependencies": {
"@opentelemetry/api": "1.6.0",
"@opentelemetry/exporter-trace-otlp-proto": "0.44.0",
"@opentelemetry/exporter-metrics-otlp-proto": "0.44.0",
"@opentelemetry/instrumentation": "0.44.0",
"@opentelemetry/instrumentation-aws-lambda": "0.37.1",
"@opentelemetry/instrumentation-aws-sdk": "0.36.1",
"@opentelemetry/instrumentation-dns": "0.32.3",
"@opentelemetry/instrumentation-express": "0.33.2",
"@opentelemetry/instrumentation-graphql": "0.35.2",
"@opentelemetry/instrumentation-grpc": "0.44.0",
"@opentelemetry/instrumentation-hapi": "0.33.1",
"@opentelemetry/instrumentation-http": "0.44.0",
"@opentelemetry/instrumentation-ioredis": "0.35.2",
"@opentelemetry/instrumentation-koa": "0.36.1",
"@opentelemetry/instrumentation-mongodb": "0.37.1",
"@opentelemetry/instrumentation-mysql": "0.34.2",
"@opentelemetry/instrumentation-net": "0.32.2",
"@opentelemetry/instrumentation-pg": "0.36.2",
"@opentelemetry/instrumentation-redis": "0.35.2",
"@opentelemetry/propagator-aws-xray": "1.3.0",
"@opentelemetry/resource-detector-aws": "1.3.2",
"@opentelemetry/resources": "1.17.1",
"@opentelemetry/sdk-metrics": "1.17.1",
"@opentelemetry/sdk-trace-base": "1.17.1",
"@opentelemetry/sdk-trace-node": "1.17.1"
}
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/api-logs": "^0.203.0",
"@opentelemetry/core": "^2.0.0",
"@opentelemetry/exporter-logs-otlp-http": "^0.203.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.203.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
"@opentelemetry/instrumentation": "^0.203.0",
"@opentelemetry/instrumentation-amqplib": "^0.50.0",
"@opentelemetry/instrumentation-aws-lambda": "^0.54.0",
"@opentelemetry/instrumentation-aws-sdk": "^0.56.0",
"@opentelemetry/instrumentation-bunyan": "^0.49.0",
"@opentelemetry/instrumentation-cassandra-driver": "^0.49.0",
"@opentelemetry/instrumentation-connect": "^0.47.0",
"@opentelemetry/instrumentation-dataloader": "^0.21.0",
"@opentelemetry/instrumentation-dns": "^0.47.0",
"@opentelemetry/instrumentation-express": "^0.52.0",
"@opentelemetry/instrumentation-fs": "^0.23.0",
"@opentelemetry/instrumentation-graphql": "^0.51.0",
"@opentelemetry/instrumentation-grpc": "^0.203.0",
"@opentelemetry/instrumentation-hapi": "^0.50.0",
"@opentelemetry/instrumentation-http": "^0.203.0",
"@opentelemetry/instrumentation-ioredis": "^0.51.0",
"@opentelemetry/instrumentation-kafkajs": "^0.12.0",
"@opentelemetry/instrumentation-knex": "^0.48.0",
"@opentelemetry/instrumentation-koa": "^0.51.0",
"@opentelemetry/instrumentation-memcached": "^0.47.0",
"@opentelemetry/instrumentation-mongodb": "^0.56.0",
"@opentelemetry/instrumentation-mongoose": "^0.50.0",
"@opentelemetry/instrumentation-mysql": "^0.49.0",
"@opentelemetry/instrumentation-mysql2": "^0.49.0",
"@opentelemetry/instrumentation-nestjs-core": "^0.49.0",
"@opentelemetry/instrumentation-net": "^0.47.0",
"@opentelemetry/instrumentation-pg": "^0.55.0",
"@opentelemetry/instrumentation-pino": "^0.50.0",
"@opentelemetry/instrumentation-redis": "^0.51.0",
"@opentelemetry/instrumentation-restify": "^0.49.0",
"@opentelemetry/instrumentation-socket.io": "^0.50.0",
"@opentelemetry/instrumentation-undici": "^0.14.0",
"@opentelemetry/instrumentation-winston": "^0.48.0",
"@opentelemetry/propagator-aws-xray": "^2.0.0",
"@opentelemetry/propagator-aws-xray-lambda": "^0.55.0",
"@opentelemetry/resource-detector-aws": "^2.0.0",
"@opentelemetry/resources": "^2.0.0",
"@opentelemetry/sdk-logs": "^0.203.0",
"@opentelemetry/sdk-metrics": "^2.0.0",
"@opentelemetry/sdk-trace-node": "^2.0.0"
},
"devDependencies": {
"@types/mocha": "^10.0.9",
"@types/sinon": "^17.0.4",
"bestzip": "^2.2.1",
"copyfiles": "^2.4.1",
"mocha": "^11.0.1",
"rimraf": "^6.0.1",
"sinon": "^21.0.0",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1",
"webpack-node-externals": "^3.0.0"
},
"sideEffects": false
}
23 changes: 23 additions & 0 deletions nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# - Use Instrumentation

export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"

# - Set the service name

if [[ -z "${OTEL_SERVICE_NAME}" ]]; then
export OTEL_SERVICE_NAME=${AWS_LAMBDA_FUNCTION_NAME};
fi

# - Set Lambda specific resource attributes

export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=${AWS_REGION},cloud.provider=aws,faas.name=${AWS_LAMBDA_FUNCTION_NAME},faas.version=${AWS_LAMBDA_FUNCTION_VERSION}";

if [[ -z "${OTEL_RESOURCE_ATTRIBUTES}" ]]; then
export OTEL_RESOURCE_ATTRIBUTES=${LAMBDA_RESOURCE_ATTRIBUTES};
else
export OTEL_RESOURCE_ATTRIBUTES="${LAMBDA_RESOURCE_ATTRIBUTES},${OTEL_RESOURCE_ATTRIBUTES}";
fi

exec "$@"
11 changes: 11 additions & 0 deletions nodejs/packages/layer/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export {};

declare global {
var configureTracerProvider: ((tracerProvider: any) => void) | undefined;
var configureTracer: ((defaultConfig: any) => any) | undefined;
var configureSdkRegistration: ((defaultSdkRegistration: any) => any) | undefined;
var configureMeter: ((defaultConfig: any) => any) | undefined;
var configureMeterProvider: ((meterProvider: any) => void) | undefined;
var configureInstrumentations: (() => any[]) | undefined;
var configureAwsInstrumentation: ((config: any) => any) | undefined;
}
Loading
Loading