Skip to content

Commit 1700bf0

Browse files
joicejoy1988Joice Joykirrg001
authored
feat(serverless-collector): added generic serverless collector (#1142)
refs https://jsw.ibm.com/browse/INSTA-759 Co-authored-by: Joice Joy <[email protected]> Co-authored-by: kirrg001 <[email protected]>
1 parent a9ed6fe commit 1700bf0

24 files changed

+1077
-8
lines changed

.tekton/generate-test-files.js

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ const groups = {
102102
'test:ci:shared-metrics': {
103103
sidecars: [],
104104
condition: ' && ! echo "$MODIFIED_FILES" | grep -q "packages/shared-metrics"'
105+
},
106+
'test:ci:serverless-collector': {
107+
sidecars: [],
108+
condition: ' && ! echo "$MODIFIED_FILES" | grep -q "packages/serverless-collector"'
105109
}
106110
};
107111

.tekton/pipeline/default-pipeline.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,29 @@ spec:
637637
workspaces:
638638
- name: output
639639
workspace: artifacts
640+
- name: test-ci-serverless-collector-task
641+
runAfter:
642+
- install-npm-dependencies
643+
taskRef:
644+
name: test-ci-serverless-collector
645+
params:
646+
- name: node-version
647+
value: $(params.node-version)
648+
- name: npm-version
649+
value: $(params.npm-version)
650+
- name: repository
651+
value: $(params.repository)
652+
- name: revision
653+
value: $(params.commit-id)
654+
- name: continuous-delivery-context-secret
655+
value: "secure-properties"
656+
- name: esm
657+
value: $(params.esm)
658+
- name: coverage
659+
value: $(params.coverage)
660+
workspaces:
661+
- name: output
662+
workspace: artifacts
640663
- name: test-ci-serverless-task
641664
runAfter:
642665
- install-npm-dependencies
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: test-ci-serverless-collector
5+
spec:
6+
sidecars:
7+
envFrom:
8+
- configMapRef:
9+
name: environment-properties
10+
params:
11+
- name: node-version
12+
value: $(params.node-version)
13+
- name: npm-version
14+
value: $(params.npm-version)
15+
- name: repository
16+
value: $(params.repository)
17+
- name: revision
18+
value: $(params.revision)
19+
- name: continuous-delivery-context-secret
20+
value: $(params.continuous-delivery-context-secret)
21+
- name: esm
22+
value: $(params.esm)
23+
- name: coverage
24+
value: $(params.coverage)
25+
workspaces:
26+
- name: output
27+
mountPath: /artifacts
28+
steps:
29+
- name: run-test-group
30+
env:
31+
- name: AWS_ACCESS_KEY_ID
32+
valueFrom:
33+
secretKeyRef:
34+
name: $(params.continuous-delivery-context-secret)
35+
key: "AWS_ACCESS_KEY_ID"
36+
- name: AWS_SECRET_ACCESS_KEY
37+
valueFrom:
38+
secretKeyRef:
39+
name: $(params.continuous-delivery-context-secret)
40+
key: "AWS_SECRET_ACCESS_KEY"
41+
- name: DB2_CONNECTION_STR
42+
valueFrom:
43+
secretKeyRef:
44+
name: $(params.continuous-delivery-context-secret)
45+
key: "DB2_CONNECTION_STR"
46+
- name: GOOGLE_APPLICATION_CREDENTIALS_CONTENT
47+
valueFrom:
48+
secretKeyRef:
49+
name: $(params.continuous-delivery-context-secret)
50+
key: "GOOGLE_APPLICATION_CREDENTIALS_CONTENT"
51+
- name: AZURE_SQL_PWD
52+
valueFrom:
53+
secretKeyRef:
54+
name: $(params.continuous-delivery-context-secret)
55+
key: "AZURE_SQL_PWD"
56+
image: node:$(params.node-version)
57+
script: |
58+
#!/bin/bash
59+
ARTIFACTS_PATH="$(workspaces.output.path)"
60+
cd $ARTIFACTS_PATH
61+
BASE_REVISION=$(git rev-parse origin/main)
62+
CIRCLE_COMPARE_URL=""
63+
MODIFIED_FILES=""
64+
GIT_COMMIT_DESC=""
65+
if [ -n "$(params.npm-version)" ]; then
66+
npm install npm@$(params.npm-version) -g
67+
fi
68+
if [ -n "$(params.revision)" ]; then
69+
CIRCLE_COMPARE_URL="$(params.repository)/compare/$BASE_REVISION..$(params.revision)"
70+
MODIFIED_FILES=$(git diff-tree --no-commit-id --name-only -r $(echo ${CIRCLE_COMPARE_URL} | cut -d/ -f 7))
71+
GIT_COMMIT_DESC=$(git log --format=%B -n 1 $(params.revision))
72+
fi
73+
echo "BASE_REVISION: $BASE_REVISION"
74+
echo "CIRCLE_COMPARE_URL: $CIRCLE_COMPARE_URL"
75+
echo "MODIFIED_FILES: $MODIFIED_FILES"
76+
echo "GIT_COMMIT_DESC: $GIT_COMMIT_DESC"
77+
if echo "$GIT_COMMIT_DESC" | grep -q '\[ci reduced\]' && ! echo "$MODIFIED_FILES" | grep -q "packages/serverless-collector"; then
78+
echo "Skipping group."
79+
touch "test:ci:serverless-collector.succeeded"
80+
exit 0
81+
fi
82+
export CI=true
83+
export GCP_PROJECT="k8s-brewery"
84+
export AZURE_SQL_USERNAME="admin@instana@nodejs-db-server"
85+
export AZURE_SQL_SERVER="nodejs-db-server.database.windows.net"
86+
export AZURE_SQL_DATABASE="azure-nodejs-test"
87+
if [ "$(params.esm)" == "true" ]; then
88+
export RUN_ESM=true
89+
if ! echo "test:ci:serverless-collector" | grep -q 'ci:collector'; then
90+
echo "Skipping tests because groupName does not contain 'ci:collector'."
91+
touch "test:ci:serverless-collector.succeeded"
92+
exit 0
93+
fi
94+
fi
95+
retry=1
96+
while [ $retry -le 3 ]; do
97+
if [ "$(params.coverage)" == "true" ]; then
98+
npm run coverage-ci --npm_command="test:ci:serverless-collector" --report_dir="test-ci-serverless-collector"
99+
else
100+
npm run "test:ci:serverless-collector"
101+
fi
102+
if [ $? -eq 0 ]; then
103+
touch "test:ci:serverless-collector.succeeded"
104+
break
105+
else
106+
if [ $retry -eq 3 ]; then
107+
touch "test:ci:serverless-collector.failed"
108+
exit 1
109+
fi
110+
retry=$((retry + 1))
111+
fi
112+
done

README.md

+15-8
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@
1717

1818
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1919

20-
## Instana npm Packages
20+
## Instana npm packages
2121

22-
This repository hosts Instana's Node.js packages. If you are an Instana user, you are probably looking for the package [@instana/collector](packages/collector/README.md) to add Instana monitoring and tracing to your Node.js applications.
22+
This repository hosts all Instana's Node.js tracer packages.
23+
24+
### Traditional server-based environments
25+
26+
* [@instana/collector](packages/collector/README.md)
27+
28+
### Serverless environments
29+
30+
* [@instana/aws-fargate](https://www.ibm.com/docs/en/instana-observability/current?topic=agents-aws-fargate#nodejs)
31+
* [@instana/aws-lambda](https://www.ibm.com/docs/en/instana-observability/current?topic=lambda-aws-native-tracing-nodejs)
32+
* [@instana/google-cloud-run](https://www.ibm.com/docs/en/instana-observability/current?topic=agents-google-cloud-run#nodejs)
33+
* [@instana/azure-container-services](https://www.ibm.com/docs/en/instana-observability/current?topic=services-azure-app-service-tracing-nodejs)
34+
35+
Please use our [@instana/serverless-collector](packages/serverless-collector/README.md) for **any other** serverless environment.
2336

24-
The following packages are meant for direct consumption by Instana users, all other packages in this repo are for internal use only:
25-
* `@instana/aws-fargate`: See <https://www.ibm.com/docs/en/instana-observability/current?topic=agents-aws-fargate#nodejs>.
26-
* `@instana/aws-lambda`: See <https://www.ibm.com/docs/en/instana-observability/current?topic=lambda-aws-native-tracing-nodejs>.
27-
* `@instana/collector`: See <https://www.ibm.com/docs/en/instana-observability/current?topic=technologies-monitoring-nodejs>.
28-
* `@instana/google-cloud-run`: See <https://www.ibm.com/docs/en/instana-observability/current?topic=agents-google-cloud-run#nodejs>.
29-
* `@instana/azure-container-services`: See <https://www.ibm.com/docs/en/instana-observability/current?topic=services-azure-app-service-tracing-nodejs>.
3037

3138
## Breaking Changes
3239

bin/run-serverless-collector-tests.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
#######################################
4+
# (c) Copyright IBM Corp. 2024
5+
#######################################
6+
7+
set -eo pipefail
8+
9+
npx lerna exec "npm run test:debug" --scope=@instana/serverless-collector
10+

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"test:ci:opentelemetry-exporter": "lerna run test:ci --stream --scope=@instana/opentelemetry-exporter",
6363
"test:ci:opentelemetry-sampler": "lerna run test:ci --stream --scope=@instana/opentelemetry-sampler",
6464
"test:ci:serverless": "lerna run test:ci --stream --scope=@instana/serverless",
65+
"test:ci:serverless-collector": "lerna run test:ci --stream --scope=@instana/serverless-collector",
6566
"test:ci:shared-metrics": "lerna run test:ci --stream --scope=@instana/shared-metrics",
6667
"typecheck": "tsc",
6768
"verify": "lerna run verify --stream",

packages/serverless-collector/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) Copyright IBM Corp. 2024
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# @instana/serverless-collector &nbsp; [![OpenTracing Badge](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
2+
3+
Monitor your Node.js applications on **any** serverless environment with Instana!
4+
5+
**Note:** This package is currently under development and marked as **beta**. Before you proceed with updating to a newer version, please ensure to review the release notes for any upcoming changes that could potentially cause compatibility issues.
6+
7+
## Restrictions
8+
9+
The serverless collector **does not** support autotracing and metrics.
10+
11+
## Installation
12+
13+
```sh
14+
npm i @instana/serverless-collector --save
15+
```
16+
17+
```js
18+
// NOTE: The package auto initializes itself.
19+
require('@instana/serverless-collector');
20+
```
21+
22+
For more in-depth documentation, refer to this [page](https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-serverless-collector-installation).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* (c) Copyright IBM Corp. 2024
3+
*/
4+
5+
'use strict';
6+
7+
/**
8+
* IMPORTANT NOTE: From Node.js version 18.19 and above, the ESM loaders operate off-thread.
9+
* Consequently, ESM instrumentation using '--experimental-loader' becomes deprecated.
10+
* Instead, we are using '--import' for loading instrumentation and relocated the Instana collector
11+
* loading to './esm-register' file.
12+
* Please note that '--import' flag is unavailable in earlier versions, hence we maintain both setups.
13+
* We will incorporate the native ESM support by using 'import-in-the-middle' its register method.
14+
*
15+
* Usage:
16+
* ENV NODE_OPTIONS='--experimental-loader=/instana/node_modules/
17+
* @instana/serverless-collector/esm-loader.mjs'
18+
*
19+
* NOTE: When using ESM, the customers have the option to set up the serverless-collector
20+
* by configuring ENV variable within the docker file. Given that serverless-collector
21+
* self-initializes, its current utilization remains unchanged.
22+
* However, there's potential for future integration where the init() method
23+
* can be invoked from this context.
24+
*/
25+
26+
import './src/index.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* (c) Copyright IBM Corp. 2024
3+
*/
4+
5+
/**
6+
* As of Node.js version 18.19 and above, ESM loaders (--experimental-loader)
7+
* are executed in a dedicated thread, separate from the main thread.
8+
* see https://github.com/nodejs/node/pull/44710.
9+
* Previously, loading the Instana collector within the loader and after the update ESM support
10+
* no longer working with v18.19 and above. To address this, we've opted to load the Instana
11+
* collector in the main thread using --import. Additionally, we aim to incorporate native ESM
12+
* support by utilizing the node register method, enabling customization of the ESM loader
13+
* with 'import-in-the-middle'.
14+
*
15+
* Usage:
16+
* ENV NODE_OPTIONS='--import /instana/node_modules/@instana/serverless-collector/esm-register.mjs server.js
17+
*/
18+
19+
// Import the initialization module for serverless collector; it self-initializes upon import
20+
// and it should be executed in the main thread.
21+
import './src/index.js';
22+
23+
// We plan to utilize this for adding native ESM support in the near future
24+
// import { register } from 'node:module';
25+
// register(./loader.mjs, import.meta.url);
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "@instana/serverless-collector",
3+
"version": "3.8.1",
4+
"description": "The Instana Node.js trace data collector for serverless environments.",
5+
"author": {
6+
"name": "Joice Joy",
7+
"email": "[email protected]"
8+
},
9+
"homepage": "https://github.com/instana/nodejs/blob/main/packages/serverless-collector/README.md",
10+
"main": "src/index.js",
11+
"files": [
12+
"src",
13+
"esm-loader.mjs",
14+
"esm-register.mjs"
15+
],
16+
"publishConfig": {
17+
"access": "public"
18+
},
19+
"directories": {
20+
"lib": "src",
21+
"test": "test"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "git+https://github.com/instana/nodejs.git"
26+
},
27+
"scripts": {
28+
"audit": "npm audit --omit=dev",
29+
"node_modules:exists": "mkdir -p node_modules",
30+
"test": "NODE_ENV=debug mocha --sort $(find test -iname '*test.js')",
31+
"test:debug": "WITH_STDOUT=true npm run test",
32+
"test:ci": "mocha --config=test/.mocharc.js --reporter mocha-multi-reporters --reporter-options configFile=reporter-config.json 'test/**/*test.js'",
33+
"lint": "eslint src test",
34+
"verify": "npm run lint && npm test",
35+
"prettier": "prettier --write 'src/**/*.js' 'test/**/*.js'"
36+
},
37+
"keywords": [
38+
"distributed-tracing",
39+
"serverless",
40+
"instana",
41+
"opentracing",
42+
"tracing"
43+
],
44+
"contributors": [
45+
{
46+
"name": "Joice Joy",
47+
"email": "[email protected]"
48+
},
49+
{
50+
"name": "Arya Mohanan",
51+
"email": "[email protected]"
52+
},
53+
{
54+
"name": "Katharina Irrgang",
55+
"email": "[email protected]"
56+
}
57+
],
58+
"bugs": {
59+
"url": "https://github.com/instana/nodejs/issues"
60+
},
61+
"license": "MIT",
62+
"dependencies": {
63+
"@instana/core": "3.8.1",
64+
"@instana/serverless": "3.8.1"
65+
}
66+
}

0 commit comments

Comments
 (0)