Improve common-utils build performance and add support for .env.local (#1466)

- Improves common-utils build process so the server is ready immediately when started. Currently, when the server starts common-utils hasn't finished building, so it starts, crashes, then restarts correctly after build. Now it runs as expected the first try.
- Adds support for `.env.local` so you can easily provide secret keys without always passing it in via the CLI
- These features already exist downstream, but they seem necessary fro oss as well.
This commit is contained in:
Brandon Pereira 2025-12-11 16:07:16 -07:00 committed by GitHub
parent 1b42180a3d
commit 65bcc1e72e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 94 additions and 11 deletions

View file

@ -36,14 +36,17 @@ collector and ClickHouse server in Docker.
To enable self-instrumentation and demo logs, you can set the `HYPERDX_API_KEY`
to your ingestion key (go to
[http://localhost:8080/team](http://localhost:8080/team) after creating your
account) and then restart the stack.
account).
ex.
To do this, create a `.env.local` file in the root of the project and add the
following:
```sh
HYPERDX_API_KEY=<YOUR_INGESTION_API_KEY_HERE> yarn run dev
HYPERDX_API_KEY=<YOUR_INGESTION_API_KEY_HERE>
```
Then restart the stack using `yarn dev`.
The core services are all hot-reloaded, so you can make changes to the code and
see them reflected in real-time.

View file

@ -8,6 +8,7 @@
],
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@dotenvx/dotenvx": "^1.51.1",
"@nx/workspace": "21.3.11",
"@typescript-eslint/eslint-plugin": "^8.48.1",
"@typescript-eslint/parser": "^8.48.1",
@ -31,10 +32,11 @@
},
"scripts": {
"setup": "yarn install && husky install",
"build:common-utils": "nx run @hyperdx/common-utils:dev:build",
"app:dev": "npx concurrently -k -n 'API,APP,ALERTS-TASK,COMMON-UTILS' -c 'green.bold,blue.bold,yellow.bold,magenta' 'nx run @hyperdx/api:dev' 'nx run @hyperdx/app:dev' 'nx run @hyperdx/api:dev-task check-alerts' 'nx run @hyperdx/common-utils:dev'",
"app:dev:local": "npx concurrently -k -n 'APP,COMMON-UTILS' -c 'blue.bold,magenta' 'nx run @hyperdx/app:dev:local' 'nx run @hyperdx/common-utils:dev'",
"app:lint": "nx run @hyperdx/app:ci:lint",
"dev": "docker compose -f docker-compose.dev.yml up -d && yarn app:dev && docker compose -f docker-compose.dev.yml down",
"dev": "yarn build:common-utils && dotenvx run --convention=nextjs -- docker compose -f docker-compose.dev.yml up -d && yarn app:dev && docker compose -f docker-compose.dev.yml down",
"dev:local": "IS_LOCAL_APP_MODE='DANGEROUSLY_is_local_app_mode💀' yarn dev",
"dev:down": "docker compose -f docker-compose.dev.yml down",
"dev:compose": "docker compose -f docker-compose.dev.yml",

View file

@ -0,0 +1,7 @@
{
"verbose": false,
"delay": 1000,
"signal": "SIGTERM",
"ext": "ts,json,js",
"watch": ["src", "../common-utils/dist/**/*.js"]
}

View file

@ -81,8 +81,8 @@
},
"scripts": {
"start": "node ./build/index.js",
"dev": "DOTENV_CONFIG_PATH=.env.development nodemon --signal SIGTERM -e ts,json --exec 'ts-node' --transpile-only -r tsconfig-paths/register -r dotenv-expand/config -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/index.ts",
"dev-task": "DOTENV_CONFIG_PATH=.env.development nodemon --signal SIGTERM -e ts,json --exec 'ts-node' --transpile-only -r tsconfig-paths/register -r dotenv-expand/config -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/tasks/index.ts",
"dev": "DOTENV_CONFIG_PATH=.env.development nodemon --exec 'ts-node' --transpile-only -r tsconfig-paths/register -r dotenv-expand/config -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/index.ts",
"dev-task": "DOTENV_CONFIG_PATH=.env.development nodemon --exec 'ts-node' --transpile-only -r tsconfig-paths/register -r dotenv-expand/config -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/tasks/index.ts",
"build": "rimraf ./build && tsc && tsc-alias && cp -r ./src/opamp/proto ./build/opamp/",
"lint": "npx eslint --quiet . --ext .ts",
"lint:fix": "npx eslint . --ext .ts --fix",

View file

@ -49,7 +49,7 @@
"typescript": "^5.9.3"
},
"scripts": {
"dev": "nodemon --watch ./src --ext ts --exec \"yarn dev:build\"",
"dev": "nodemon --on-change-only --watch ./src --ext ts --exec \"yarn dev:build\"",
"dev:build": "tsup && tsc --emitDeclarationOnly --declaration",
"build": "tsup",
"ci:build": "tsup",

View file

@ -3373,6 +3373,25 @@ __metadata:
languageName: node
linkType: hard
"@dotenvx/dotenvx@npm:^1.51.1":
version: 1.51.1
resolution: "@dotenvx/dotenvx@npm:1.51.1"
dependencies:
commander: "npm:^11.1.0"
dotenv: "npm:^17.2.1"
eciesjs: "npm:^0.4.10"
execa: "npm:^5.1.1"
fdir: "npm:^6.2.0"
ignore: "npm:^5.3.0"
object-treeify: "npm:1.1.33"
picomatch: "npm:^4.0.2"
which: "npm:^4.0.0"
bin:
dotenvx: src/cli/dotenvx.js
checksum: 10c0/61360547606c89e4bce2971fb524b54d8a1d03545dc17591562ba02affff18ff395ae64205a14fe6b975beaec82014f0bd18bed2c2acbd7bba6eb17a83fcd477
languageName: node
linkType: hard
"@dual-bundle/import-meta-resolve@npm:^4.2.1":
version: 4.2.1
resolution: "@dual-bundle/import-meta-resolve@npm:4.2.1"
@ -3380,6 +3399,15 @@ __metadata:
languageName: node
linkType: hard
"@ecies/ciphers@npm:^0.2.4":
version: 0.2.5
resolution: "@ecies/ciphers@npm:0.2.5"
peerDependencies:
"@noble/ciphers": ^1.0.0
checksum: 10c0/fcc08327216d225310596dc5d6a25da919e641e271c1895384e068fdd910e835271a103c5105aaa8ea24b33931b7d1975341b044919d38fd586e8ad8e0f33be6
languageName: node
linkType: hard
"@emnapi/core@npm:^1.1.0, @emnapi/core@npm:^1.4.3":
version: 1.7.1
resolution: "@emnapi/core@npm:1.7.1"
@ -6103,7 +6131,23 @@ __metadata:
languageName: node
linkType: hard
"@noble/hashes@npm:^1.1.5":
"@noble/ciphers@npm:^1.3.0":
version: 1.3.0
resolution: "@noble/ciphers@npm:1.3.0"
checksum: 10c0/3ba6da645ce45e2f35e3b2e5c87ceba86b21dfa62b9466ede9edfb397f8116dae284f06652c0cd81d99445a2262b606632e868103d54ecc99fd946ae1af8cd37
languageName: node
linkType: hard
"@noble/curves@npm:^1.9.7":
version: 1.9.7
resolution: "@noble/curves@npm:1.9.7"
dependencies:
"@noble/hashes": "npm:1.8.0"
checksum: 10c0/150014751ebe8ca06a8654ca2525108452ea9ee0be23430332769f06808cddabfe84f248b6dbf836916bc869c27c2092957eec62c7506d68a1ed0a624017c2a3
languageName: node
linkType: hard
"@noble/hashes@npm:1.8.0, @noble/hashes@npm:^1.1.5, @noble/hashes@npm:^1.8.0":
version: 1.8.0
resolution: "@noble/hashes@npm:1.8.0"
checksum: 10c0/06a0b52c81a6fa7f04d67762e08b2c476a00285858150caeaaff4037356dd5e119f45b2a530f638b77a5eeca013168ec1b655db41bae3236cb2e9d511484fc77
@ -12283,6 +12327,13 @@ __metadata:
languageName: node
linkType: hard
"commander@npm:^11.1.0":
version: 11.1.0
resolution: "commander@npm:11.1.0"
checksum: 10c0/13cc6ac875e48780250f723fb81c1c1178d35c5decb1abb1b628b3177af08a8554e76b2c0f29de72d69eef7c864d12613272a71fabef8047922bc622ab75a179
languageName: node
linkType: hard
"commander@npm:^2.19.0, commander@npm:^2.20.0":
version: 2.20.3
resolution: "commander@npm:2.20.3"
@ -13576,7 +13627,7 @@ __metadata:
languageName: node
linkType: hard
"dotenv@npm:^17.2.3":
"dotenv@npm:^17.2.1, dotenv@npm:^17.2.3":
version: 17.2.3
resolution: "dotenv@npm:17.2.3"
checksum: 10c0/c884403209f713214a1b64d4d1defa4934c2aa5b0002f5a670ae298a51e3c3ad3ba79dfee2f8df49f01ae74290fcd9acdb1ab1d09c7bfb42b539036108bb2ba0
@ -13623,6 +13674,18 @@ __metadata:
languageName: node
linkType: hard
"eciesjs@npm:^0.4.10":
version: 0.4.16
resolution: "eciesjs@npm:0.4.16"
dependencies:
"@ecies/ciphers": "npm:^0.2.4"
"@noble/ciphers": "npm:^1.3.0"
"@noble/curves": "npm:^1.9.7"
"@noble/hashes": "npm:^1.8.0"
checksum: 10c0/b4f562f3811722844a0fe25ed7e0fcee755be070b611d918c5d672327c660a675dd9e32cb596c87be05dfdd48dcbef90bb2b855e6e3266f9354505adf9e111e4
languageName: node
linkType: hard
"ee-first@npm:1.1.1":
version: 1.1.1
resolution: "ee-first@npm:1.1.1"
@ -15153,7 +15216,7 @@ __metadata:
languageName: node
linkType: hard
"fdir@npm:^6.5.0":
"fdir@npm:^6.2.0, fdir@npm:^6.5.0":
version: 6.5.0
resolution: "fdir@npm:6.5.0"
peerDependencies:
@ -16642,6 +16705,7 @@ __metadata:
resolution: "hyperdx@workspace:."
dependencies:
"@changesets/cli": "npm:^2.26.2"
"@dotenvx/dotenvx": "npm:^1.51.1"
"@nx/workspace": "npm:21.3.11"
"@typescript-eslint/eslint-plugin": "npm:^8.48.1"
"@typescript-eslint/parser": "npm:^8.48.1"
@ -16722,7 +16786,7 @@ __metadata:
languageName: node
linkType: hard
"ignore@npm:^5.1.8":
"ignore@npm:^5.1.8, ignore@npm:^5.3.0":
version: 5.3.2
resolution: "ignore@npm:5.3.2"
checksum: 10c0/f9f652c957983634ded1e7f02da3b559a0d4cc210fca3792cb67f1b153623c9c42efdc1c4121af171e295444459fc4a9201101fb041b1104a3c000bccb188337
@ -21887,6 +21951,13 @@ __metadata:
languageName: node
linkType: hard
"object-treeify@npm:1.1.33":
version: 1.1.33
resolution: "object-treeify@npm:1.1.33"
checksum: 10c0/5b735ac552200bf14f9892ce58295303e8d15a8cc7a0fd4fe6ff99923ab0c196fb70a870ab2a0eefc6820c4acb49e614b88c72d344b9c6bd22584a3efbd386fe
languageName: node
linkType: hard
"object.assign@npm:^4.1.4, object.assign@npm:^4.1.7":
version: 4.1.7
resolution: "object.assign@npm:4.1.7"