Skip to content

chore: add test-services scripts per package #2932

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9f52a4e
chore: rename setup script
david-luna Jul 9, 2025
b71a1af
chore: add scripts to cassandra driver instr
david-luna Jul 9, 2025
240359f
chore: add scripts to iosredis instrumentation
david-luna Jul 9, 2025
dafcf86
chore: update sceript to a batch of instrumentations
david-luna Jul 9, 2025
6b88fdb
chore: updates cripts for oracle and pg instrumentations
david-luna Jul 9, 2025
9a8d2ac
chore: update script for a batch of pacakges
david-luna Jul 9, 2025
9785201
chore: organize npm scripts
david-luna Jul 9, 2025
2eef913
chore: fix lint issues
david-luna Jul 9, 2025
536dab5
Merge branch 'main' into add-services-scripts-per-package
david-luna Jul 9, 2025
813a7c7
chore: add cros-env where needed
david-luna Jul 9, 2025
7d7d919
chore: remove unused test utils for docker
david-luna Jul 9, 2025
188d6a1
chore: update cassandra instr scripts
david-luna Jul 9, 2025
a2e0266
Merge branch 'main' into add-services-scripts-per-package
david-luna Jul 9, 2025
f9711f5
Merge branch 'main' into add-services-scripts-per-package
david-luna Jul 21, 2025
4e8e846
Merge branch 'main' into add-services-scripts-per-package
david-luna Jul 23, 2025
76f9219
chore: cat file for debugging
david-luna Jul 23, 2025
2888fc4
Merge branch 'add-services-scripts-per-package' of github.com:david-l…
david-luna Jul 23, 2025
a3ac2f2
chore: fix conflicts with main
david-luna Jul 23, 2025
dc750b5
Merge branch 'main' into add-services-scripts-per-package
david-luna Jul 31, 2025
bb454f5
chore: revert instr-wiston test scripts to use the one from main
david-luna Jul 31, 2025
8c2783d
chore: remove env file in mysql2 instr
david-luna Jul 31, 2025
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
22 changes: 10 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The required steps to start development on a pacakge are:

- `npm ci` from root folder to install dependencies ([see npm-ci docs](https://docs.npmjs.com/cli/v10/commands/npm-ci))
- `cd` into the pacakge you want to apply changes.
- `npm run setup:dev` compiles the TypeScript files for this package and its dependencies within the repository.
- `npm run compile:with-dependencies` compiles the TypeScript files for this package and its dependencies within the repository.
Copy link
Contributor Author

@david-luna david-luna Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for reviewer: script name has changed to be more explicit about what it does. you will see this change on each package.json that has it


Then you can proceed to do apply the changes and use the scripts below for development workflow

Expand Down Expand Up @@ -146,23 +146,21 @@ npm test
However, some instrumentations require test-services to be running (e.g. the `instrumentation-mongodb` package requires a MongoDB server). Use the `test-services`-related npm scripts to start all required services in Docker and then run the tests with the appropriate configuration to use those services:

```sh
npm run test-services:start # starts services in Docker
npm run test:with-services-config # runs 'npm test' with envvars from test/test-services.env
npm run test-services:stop # stops services in Docker
npm run test-services:start # starts services in Docker
npm run test:with-services-env # runs 'npm test' with envvars from test/test-services.env
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to reviewer: this was a typo from #2886

npm run test-services:stop # stops services in Docker
```

If you only want to test a single package (e.g. the `instrumentation-mongodb`) you can `cd` into it and run the tests after you started the services.
If you only want to test a single package that dfepends on a service (e.g. the `instrumentation-mongodb`) you can `cd` into it and
use the same scripts for testing. In this case the script will only start the services needed to test the package.

```sh
npm run test-services:start # starts services in Docker
cd packages/instrumentation-mongodb # get into the instrumenation folder
RUN_MONGODB_TESTS=1 npm test # run the test with the proper config (check each package)
cd ../../.. # go back to root folder
npm run test-services:stop # stops services in Docker
cd packages/instrumentation-mongodb # get into the instrumenation folder
npm run test-services:start # start the MongoDB service in Docker
npm run test:with-services-env # runs 'npm test' with envvars from test/test-services.env
npm run test-services:stop # stop MongoDB service in Docker
```

NOTE: scripts for each package will be added to avoid extra consumption of resources and improve the development experience.

### Benchmarks

When two or more approaches must be compared, please write a benchmark in the benchmark/index.js module so that we can keep track of the most efficient algorithm.
Expand Down
4 changes: 2 additions & 2 deletions incubator/opentelemetry-sampler-aws-xray/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
],
"repository": "open-telemetry/opentelemetry-js-contrib",
"scripts": {
"setup:dev": "nx run-many -t compile -p @opentelemetry/sampler-aws-xray",
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/sampler-aws-xray",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
"prepublishOnly": "npm run compile",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc mocha 'test/**/*.test.ts'",
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/auto-configuration-propagators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/auto-configuration-propagators",
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/auto-configuration-propagators",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prepublishOnly": "npm run compile",
Expand Down
2 changes: 1 addition & 1 deletion packages/auto-instrumentations-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/auto-instrumentations-node",
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/auto-instrumentations-node",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prepublishOnly": "npm run compile",
Expand Down
2 changes: 1 addition & 1 deletion packages/auto-instrumentations-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"scripts": {
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"setup:dev": "nx run-many -t compile -p @opentelemetry/auto-instrumentations-web",
"compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/auto-instrumentations-web",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prepublishOnly": "npm run compile",
Expand Down
2 changes: 1 addition & 1 deletion packages/baggage-log-record-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/baggage-log-record-processor",
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/baggage-log-record-processor",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prewatch": "npm run precompile",
Expand Down
2 changes: 1 addition & 1 deletion packages/baggage-span-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/baggage-span-processor",
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/baggage-span-processor",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prepublishOnly": "npm run compile",
Expand Down
4 changes: 2 additions & 2 deletions packages/contrib-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"access": "public"
},
"scripts": {
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/contrib-test-utils",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"setup:dev": "nx run-many -t compile -p @opentelemetry/contrib-test-utils",
"compile": "tsc -p .",
"prepublishOnly": "npm run compile",
"watch": "tsc -w"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/contrib-test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ export type { TestSpan, RunTestFixtureOptions } from './test-fixtures';
export {
assertPropagation,
assertSpan,
cleanUpDocker,
getPackageVersion,
initMeterProvider,
startDocker,
TestMetricReader,
} from './test-utils';
export type { TimedEvent } from './test-utils';
Expand Down
57 changes: 0 additions & 57 deletions packages/contrib-test-utils/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import * as childProcess from 'child_process';
import {
HrTime,
Span,
Expand All @@ -33,62 +32,6 @@ import * as path from 'path';
import * as fs from 'fs';
import { InstrumentationBase } from '@opentelemetry/instrumentation';

const dockerRunCmds = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for reviewer: not needed anymore

cassandra:
'docker run --rm -d --name otel-cassandra -p 9042:9042 bitnami/cassandra:3',
memcached:
'docker run --rm -d --name otel-memcached -p 11211:11211 memcached:1.6.9-alpine',
mssql:
'docker run --rm -d --name otel-mssql -p 1433:1433 -e MSSQL_SA_PASSWORD=mssql_passw0rd -e ACCEPT_EULA=Y mcr.microsoft.com/mssql/server:2022-latest',
mysql:
'docker run --rm -d --name otel-mysql -p 33306:3306 -e MYSQL_ROOT_PASSWORD=rootpw -e MYSQL_DATABASE=test_db -e MYSQL_USER=otel -e MYSQL_PASSWORD=secret mysql:5.7 --log_output=TABLE --general_log=ON',
oracledb:
'docker run --rm -d --name otel-oracledb -p 1521:1521 -e ORACLE_PASSWORD=oracle -e APP_USER=otel -e APP_USER_PASSWORD=secret gvenzl/oracle-free:slim',
postgres:
'docker run --rm -d --name otel-postgres -p 54320:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=otel_pg_database postgres:16-alpine',
redis: 'docker run --rm -d --name otel-redis -p 63790:6379 redis:alpine',
};

export function startDocker(db: keyof typeof dockerRunCmds) {
const tasks = [run(dockerRunCmds[db])];

for (let i = 0; i < tasks.length; i++) {
const task = tasks[i];
if (task && task.code !== 0) {
console.error('Failed to start container!');
console.error(task.output);
return false;
}
}
return true;
}

export function cleanUpDocker(db: keyof typeof dockerRunCmds) {
run(`docker stop otel-${db}`);
}

function run(cmd: string) {
try {
const proc = childProcess.spawnSync(cmd, {
shell: true,
});
const output = Buffer.concat(
proc.output.filter(c => c) as Buffer[]
).toString('utf8');
if (proc.status !== 0) {
console.error('Failed run command:', cmd);
console.error(output);
}
return {
code: proc.status,
output,
};
} catch (e) {
console.log(e);
return;
}
}

export const assertSpan = (
span: ReadableSpan,
kind: SpanKind,
Expand Down
2 changes: 1 addition & 1 deletion packages/host-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/host-metrics",
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/host-metrics",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"prepublishOnly": "npm run compile",
Expand Down
4 changes: 2 additions & 2 deletions packages/id-generator-aws-xray/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"directory": "packages/id-generator-aws-xray"
},
"scripts": {
"setup:dev": "nx run-many -t compile -p @opentelemetry/id-generator-aws-xray",
"compile": "tsc --build tsconfig.json tsconfig.esm.json",
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
"compile": "tsc --build tsconfig.json tsconfig.esm.json",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/id-generator-aws-xray",
"test": "nyc mocha test/**/*.test.ts",
"test:browser": "nyc karma start --single-run",
"lint": "eslint . --ext .ts",
Expand Down
10 changes: 7 additions & 3 deletions packages/instrumentation-amqplib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-amqplib",
"compile": "tsc -p .",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-amqplib",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"lint:readme": "node ../../scripts/lint-readme.js",
"prepublishOnly": "npm run compile",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
"test-all-versions": "tav",
"test-all-versions:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm run test-all-versions",
"test-services:start": "cd ../.. && npm run test-services:start rabbitmq",
"test-services:stop": "cd ../.. && npm run test-services:stop rabbitmq",
"version:update": "node ../../scripts/version-update.js",
"watch": "tsc -w",
"test:docker:run": "docker run -d --hostname demo-amqplib-rabbit --name amqplib-unittests -p 22221:5672 --env RABBITMQ_DEFAULT_USER=username --env RABBITMQ_DEFAULT_PASS=password rabbitmq:3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for reviewer: scripts with docker commands have been deleted because now the service is controlled via test-services:start and test-services:stop

"watch": "tsc -w"
},
"peerDependencies": {
"@opentelemetry/api": "^1.3.0"
Expand All @@ -61,6 +64,7 @@
"@types/node": "18.18.14",
"@types/sinon": "17.0.4",
"amqplib": "0.8.0",
"cross-env": "7.0.3",
"expect": "29.2.0",
"lodash": "4.17.21",
"nyc": "17.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/instrumentation-aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"lint:readme": "node ../../scripts/lint-readme.js",
"prepublishOnly": "npm run compile",
"version:update": "node ../../scripts/version-update.js",
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-lambda",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-lambda",
"compile": "tsc -p ."
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/instrumentation-aws-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-sdk",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-sdk",
"compile": "tsc -p .",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
Expand Down
2 changes: 1 addition & 1 deletion packages/instrumentation-bunyan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {
"clean": "rimraf build/*",
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-bunyan",
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-bunyan",
"compile": "tsc -p .",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
Expand Down
Loading
Loading