Skip to content

fix(aws-lambda): added performance improvements #1315

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

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
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
651 changes: 651 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@apollo/gateway": "^2.10.0",
"@apollo/subgraph": "^2.10.0",
"@aws-sdk/client-dynamodb": "^3.758.0",
"@aws-sdk/client-cloudwatch-logs": "^3.696.0",
"@aws-sdk/client-dynamodb-v3": "npm:@aws-sdk/[email protected]",
"@aws-sdk/client-kinesis": "^3.758.0",
"@aws-sdk/client-kms": "^3.679.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-fargate/src/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function init() {
backendConnector.init({
config,
identityProvider,
stopSendingOnFailure: false,
// TODO: false or true?
propagateErrorsUpstream: true,
defaultTimeout: 950
});
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions packages/aws-lambda/lambdas/many-spans/bin/create-zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -eEuo pipefail
#######################################
# (c) Copyright IBM Corp. 2025
#######################################


cd `dirname $BASH_SOURCE`/..

source ../bin/create-zip-util
createZip

48 changes: 48 additions & 0 deletions packages/aws-lambda/lambdas/many-spans/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* (c) Copyright IBM Corp. 2024
*/

/* eslint-disable indent, import/order, no-console, no-await-in-loop */

'use strict';

// eslint-disable-next-line import/no-extraneous-dependencies
const instana = require('@instana/aws-lambda');

const delay = ms => {
return new Promise(resolve => setTimeout(resolve, ms));
};

const DELAY = process.env.DELAY || 100;
const ITERATIONS = process.env.ITERATIONS || 100;

// exports.handler = instana.wrap(async () => {
// console.log('Running handler.');

// for (let i = 0; i < ITERATIONS; i++) {
// await instana.sdk.async.startExitSpan(`custom-span ${i}`);
// await delay(DELAY);
// instana.sdk.async.completeExitSpan();
// }

// return {
// body: {
// message: 'Stan says hi!'
// }
// };
// });
exports.handler = async () => {
console.log('Running handler.');

for (let i = 0; i < ITERATIONS; i++) {
await instana.sdk.async.startExitSpan(`custom-span ${i}`);
await delay(DELAY);
instana.sdk.async.completeExitSpan();
}

return {
body: {
message: 'Stan says hi!'
}
};
};
13 changes: 13 additions & 0 deletions packages/aws-lambda/lambdas/many-spans/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions packages/aws-lambda/lambdas/many-spans/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "many-spans",
"description": "Testing lots of spans.",
"version": "1.0.0",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/instana/nodejs.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Katharina Irrgang <[email protected]>",
"license": "MIT"
}
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions packages/aws-lambda/load-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# AWS Lambda + Layer Load Test

## Links

https://www.ibm.com/docs/en/instana-observability/current?topic=lambda-aws-native-tracing-nodejs#architecture-x8664

## Deploy released & test

This is helpful to test against the released behavior.
Uses the released layer, creates the zip and deploys the fn.

```sh
RELEASED=1 INSTANA_ENDPOINT_URL=... INSTANA_AGENT_KEY=... REGION=us-east-1 ./load-test/deploy.sh
RELEASED=1 node ./load-test/test.js
./load-test/cleanup.sh
```

## Deploy local & test

Publishes the local experimental lambda layer, creates the zip and deploys the fn.

```sh
INSTANA_ENDPOINT_URL=... INSTANA_AGENT_KEY=... REGION=us-east-1 ./load-test/deploy.sh
node ./load-test/test.js
./load-test/cleanup.sh
```
19 changes: 19 additions & 0 deletions packages/aws-lambda/load-test/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

#######################################
# (c) Copyright IBM Corp. 2024
#######################################

set -eo pipefail

REGION=$REGION

if [[ -z $REGION ]]; then
REGION=us-east-1
fi

aws lambda delete-function-url-config --function-name teamnodejstracer-many-spans --region $REGION || true
aws lambda delete-function --function-name teamnodejstracer-many-spans --region $REGION || true
aws lambda delete-function-url-config --function-name teamnodejstracer-released-many-spans --region $REGION || true
aws lambda delete-function --function-name teamnodejstracer-released-many-spans --region $REGION || true

122 changes: 122 additions & 0 deletions packages/aws-lambda/load-test/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env bash

#######################################
# (c) Copyright IBM Corp. 2024
#######################################

set -eo pipefail

command -v aws >/dev/null 2>&1 || {
cat <<EOF >&2
The AWS command line tool needs to be installed but it isn't. See https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html or https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html etc. for instructions.

Aborting.
EOF
exit 1
}
command -v jq >/dev/null 2>&1 || {
cat <<EOF >&2
The executable jq needs to be installed but it isn't.

Aborting.
EOF
exit 1
}
command -v curl >/dev/null 2>&1 || {
cat <<EOF >&2
The executable curl needs to be installed but it isn't.

Aborting.
EOF
exit 1
}

LAYER_ARN=$LAYER_ARN
RELEASED=$RELEASED
INSTANA_ENDPOINT_URL=$INSTANA_ENDPOINT_URL
INSTANA_AGENT_KEY=$INSTANA_AGENT_KEY
REGION=$REGION
LAYER_NAME=$LAYER_NAME

if [[ -z $REGION ]]; then
REGION=us-east-1
fi

if [[ -z $INSTANA_ENDPOINT_URL ]]; then
echo "INSTANA_ENDPOINT_URL is not set. Aborting."
exit 1
fi

if [[ -z $INSTANA_AGENT_KEY ]]; then
echo "INSTANA_AGENT_KEY is not set. Aborting."
exit 1
fi

if [[ -z $RELEASED ]]; then
RELEASED=0
fi

# if RELEASED is 0
if [[ $RELEASED -eq 0 ]]; then
FUNCTION_NAME_PREFIX=teamnodejstracer
LAYER_NAME=experimental-instana-nodejs-with-extension
LAYER_ARN="Will be set after upload..."
else
FUNCTION_NAME_PREFIX=teamnodejstracer-released
LAYER_NAME=instana-nodejs
LAYER_ARN="Will be downloaded from AWS based on the REGION..."
fi

printf "\n#### Summary ####\n\n"
echo "LAYER NAME: $LAYER_NAME"
echo "REGION:: $REGION"
echo "LAYER_ARN: $LAYER_ARN"
echo "RELEASED: $RELEASED"
echo "FUNCTION_NAME_PREFIX: $FUNCTION_NAME_PREFIX"
echo "INSTANA_ENDPOINT_URL: $INSTANA_ENDPOINT_URL"
echo "INSTANA_AGENT_KEY: $INSTANA_AGENT_KEY"
printf "####\n\n"

if [[ -z $NO_PROMPT ]]; then
while true; do
read -p "Do you wish to continue (yes or no)? " yn
case $yn in
[Yy]* ) echo "Let's go!"; break;;
[Nn]* ) exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi

cd ./lambdas
echo "Creating zip file for 'many-spans' lambda..."
BUILD_LAMBDAS_WITH=local bin/create-zip.sh many-spans

cd ../
cd ./layer/bin

if [[ $RELEASED -eq 0 ]]; then
echo "Uploading experimental layer..."

REGIONS=$REGION SKIP_DOCKER_IMAGE=true BUILD_LAYER_WITH=local LAYER_NAME=$LAYER_NAME ./publish-layer.sh
LAYER_ARN=$(aws lambda list-layer-versions --layer-name $LAYER_NAME --region $REGION | jq -r '.LayerVersions[0].LayerVersionArn')

echo "Layer ARN: $LAYER_ARN"
echo "Deploying 'many-spans' lambda..."

cd ../../
cd ./lambdas
FUNCTION_NAME_PREFIX=$FUNCTION_NAME_PREFIX TIMEOUT=60 FUNCTION_URL=true REGION=$REGION LAYER_ARN=$LAYER_ARN bin/deploy-zip.sh zip/many-spans.zip
sleep 5
else
echo "Using released layer..."
echo "Deploying 'many-spans' lambda..."

cd ../../
cd ./lambdas
unset $LAYER_ARN
FUNCTION_NAME_PREFIX=$FUNCTION_NAME_PREFIX TIMEOUT=60 FUNCTION_URL=true REGION=$REGION bin/deploy-zip.sh zip/many-spans.zip
sleep 5
fi


Loading