From d7875a563e657ff50d857c70491478583af90b89 Mon Sep 17 00:00:00 2001 From: Brett Beutell Date: Mon, 26 Feb 2024 18:02:14 +0100 Subject: [PATCH] Prepare for release 1.0.1 (#151) * Add a troubleshooting section to the Contributing > Common Commands doc * Do not rely on global biome in justfile * Modify autometrics/src/platform.node.ts to work in deno test env (import process) * Add a test for infinite looping when readClosest cannot find a file in node.js * Format files to appease biome * Clean node modules from parcle transformer * HACK - fix type issues with parcel-transformer when building * Fix build-all and add utility for reloading deno cache * Update changelog * Bump version and update yarn lockfiles for examples * Remove clean-all from build-all because ci does not have bash extensions we need * Update contributing doc troubleshooting --- CHANGELOG.md | 10 +++++++ CONTRIBUTING.md | 9 +++++++ examples/fastify/yarn.lock | 6 ++--- examples/react-app-experimental/yarn.lock | 6 ++--- justfile | 26 ++++++++++++++++--- package.json | 2 +- packages/autometrics/src/platform.node.ts | 5 ++-- packages/autometrics/src/temporaryMeter.ts | 15 ++++++++--- .../autometrics/tests/platform.node.test.ts | 16 ++++++++++++ .../parcel-transformer-autometrics/justfile | 2 +- .../src/types.d.ts | 7 +++++ 11 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 packages/autometrics/tests/platform.node.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ccac18..fead9da8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [v1.0.1] + +This release fixes two issues. Thanks to @benjibuiltit for his contributions! + +### Fixed + +- #149 - Fixed an issue where autometrics in a Node.js environment would fail if it was not running inside a git repository +- #150 - Fixed rendering of a function name and module when using the `relfect-metadata` package + + ## [v1.0.0] This release features full compliance with the diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2a2b8e32..432dfa56 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,6 +33,15 @@ The `justfile` has several commands that are useful during development: Run `just -l` for a list of all available commands. +#### Troubleshooting + +If you run into dependency-related issues with the `justfile` build commands, you may need to do one or any of the following: + +- Remove `node_modules` (`just clean-all`) +- Reload all cached deno dependencies (`just reload-all`) + +Note that you'll need several tools installed to run the examples. This includes `bun` and `deno`. + ### Overview #### `packages/autometrics` diff --git a/examples/fastify/yarn.lock b/examples/fastify/yarn.lock index 447c2e98..37fb83e0 100644 --- a/examples/fastify/yarn.lock +++ b/examples/fastify/yarn.lock @@ -5,7 +5,7 @@ __metadata: version: 6 cacheKey: 8 -"@autometrics/autometrics@1.0.0, @autometrics/autometrics@workspace:../../dist/autometrics": +"@autometrics/autometrics@1.0.1, @autometrics/autometrics@workspace:../../dist/autometrics": version: 0.0.0-use.local resolution: "@autometrics/autometrics@workspace:../../dist/autometrics" dependencies: @@ -28,7 +28,7 @@ __metadata: version: 0.0.0-use.local resolution: "@autometrics/exporter-prometheus@portal:../../dist/exporter-prometheus::locator=fastify-example%40workspace%3A." dependencies: - "@autometrics/autometrics": 1.0.0 + "@autometrics/autometrics": 1.0.1 "@opentelemetry/api": 1.7.0 "@opentelemetry/exporter-prometheus": 0.45.0 "@opentelemetry/sdk-metrics": 1.18.0 @@ -39,7 +39,7 @@ __metadata: version: 0.0.0-use.local resolution: "@autometrics/exporter-prometheus@workspace:../../dist/exporter-prometheus" dependencies: - "@autometrics/autometrics": 1.0.0 + "@autometrics/autometrics": 1.0.1 "@opentelemetry/api": 1.7.0 "@opentelemetry/exporter-prometheus": 0.45.0 "@opentelemetry/sdk-metrics": 1.18.0 diff --git a/examples/react-app-experimental/yarn.lock b/examples/react-app-experimental/yarn.lock index bcbcb3d4..d2ba235c 100644 --- a/examples/react-app-experimental/yarn.lock +++ b/examples/react-app-experimental/yarn.lock @@ -15,7 +15,7 @@ __metadata: languageName: node linkType: hard -"@autometrics/autometrics@1.0.0, @autometrics/autometrics@workspace:../../dist/autometrics": +"@autometrics/autometrics@1.0.1, @autometrics/autometrics@workspace:../../dist/autometrics": version: 0.0.0-use.local resolution: "@autometrics/autometrics@workspace:../../dist/autometrics" dependencies: @@ -38,7 +38,7 @@ __metadata: version: 0.0.0-use.local resolution: "@autometrics/exporter-otlp-http@portal:../../dist/exporter-otlp-http::locator=react-app-example%40workspace%3A." dependencies: - "@autometrics/autometrics": 1.0.0 + "@autometrics/autometrics": 1.0.1 "@opentelemetry/api": 1.7.0 "@opentelemetry/exporter-metrics-otlp-http": 0.45.0 "@opentelemetry/sdk-metrics": 1.18.0 @@ -49,7 +49,7 @@ __metadata: version: 0.0.0-use.local resolution: "@autometrics/exporter-prometheus@workspace:../../dist/exporter-prometheus" dependencies: - "@autometrics/autometrics": 1.0.0 + "@autometrics/autometrics": 1.0.1 "@opentelemetry/api": 1.7.0 "@opentelemetry/exporter-prometheus": 0.45.0 "@opentelemetry/sdk-metrics": 1.18.0 diff --git a/justfile b/justfile index 05eea82e..6c0f9b12 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,7 @@ alias b := build alias l := lint alias t := test +alias reload-all := reload-all-deno-cache examples := "deno-fresh express faas-experimental fastify hono-bun react-app-experimental" @@ -8,6 +9,8 @@ lib_packages := "autometrics exporter-otlp-http exporter-prometheus exporter-pro test_permissions := "--allow-env --allow-net --allow-read --allow-sys --allow-write" +biome_permissions := "--allow-env --allow-read --allow-run --allow-write" + build: (build-npm "") build-npm version: @@ -22,13 +25,17 @@ build-examples: popd done +# NOTE - You may need to run `just clean` in the project root before running this command build-parcel-transformer: cd packages/parcel-transformer-autometrics; just build +# NOTE - You may need to run `just clean` in the project root before running this command build-typescript-plugin: cd packages/typescript-plugin; just build -build-all: build build-examples build-parcel-transformer build-typescript-plugin +# NOTE - Build the non-deno things first, then the deno things (this order is important) +# NOTE - If this fails, try running `clean-all` then run this command again +build-all: build-parcel-transformer build-typescript-plugin build build-examples test: deno test {{test_permissions}} packages/autometrics @@ -87,14 +94,25 @@ clean-typescript-plugin: clean-all: clean clean-examples clean-parcel-transformer clean-typescript-plugin +reload-all-deno-cache: + #!/usr/bin/env bash + set -euxo pipefail + for package in {{lib_packages}}; do + pushd "packages/$package" + # Ignore directories named `tests` or `dist` or `node_modules` + # Then reload the Deno cache for any imports in files that end in .ts or .js + find . \( -type d \( -name "tests" -o -name "dist" -o -name "node_modules" \) -prune \) -o \( -type f \( -name "*.ts" \) -exec deno cache --reload {} + \) + popd + done + fix: - biome check --apply-unsafe packages + deno run {{biome_permissions}} npm:@biomejs/biome check --apply-unsafe packages format: - biome format --write packages + deno run {{biome_permissions}} npm:@biomejs/biome format --write packages lint: - biome ci packages + deno run {{biome_permissions}} npm:@biomejs/biome ci packages release-lib: #!/usr/bin/env bash diff --git a/package.json b/package.json index 1f4dc104..0ae16afd 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": true, "name": "autometrics-monorepo", "packageManager": "yarn@3.6.3", - "version": "1.0.0", + "version": "1.0.1", "workspaces": [ "dist/autometrics", "dist/exporter-otlp-http", diff --git a/packages/autometrics/src/platform.node.ts b/packages/autometrics/src/platform.node.ts index 0dca8e5a..14961a1b 100644 --- a/packages/autometrics/src/platform.node.ts +++ b/packages/autometrics/src/platform.node.ts @@ -5,6 +5,7 @@ import { AsyncLocalStorage } from "node:async_hooks"; import { readFileSync } from "node:fs"; import { dirname, join, parse } from "node:path"; +import * as process from "node:process"; import { AUTOMETRICS_DEFAULT_SERVICE_NAME } from "./constants.ts"; import { getGitRepositoryUrl, getPackageStringField } from "./platformUtils.ts"; @@ -118,7 +119,7 @@ export function getALSInstance() { * @internal */ export function isRootPath(pathToCheck: string): boolean { - return pathToCheck == parse(getCwd()).root; + return pathToCheck === parse(getCwd()).root; } function detectPackageName(): string | undefined { @@ -142,7 +143,7 @@ function detectRepositoryUrl(): string | undefined { } catch {} } -function readClosest(path: string): Uint8Array { +export function readClosest(path: string): Uint8Array { let basePath = getCwd(); while (basePath.length > 0) { try { diff --git a/packages/autometrics/src/temporaryMeter.ts b/packages/autometrics/src/temporaryMeter.ts index d0da03d4..d7eb1b38 100644 --- a/packages/autometrics/src/temporaryMeter.ts +++ b/packages/autometrics/src/temporaryMeter.ts @@ -293,7 +293,10 @@ class TemporaryCounter > = []; private _counter: Counter | undefined; - constructor(public name: string, public options?: MetricOptions) {} + constructor( + public name: string, + public options?: MetricOptions, + ) {} add(value: number, attributes?: AttributesTypes, context?: Context): void { if (this._counter) { @@ -321,7 +324,10 @@ class TemporaryHistogram [number, AttributesTypes | undefined, Context | undefined] > = []; - constructor(public name: string, public options?: MetricOptions) {} + constructor( + public name: string, + public options?: MetricOptions, + ) {} record(value: number, attributes?: AttributesTypes, context?: Context): void { if (this._histogram) { @@ -350,7 +356,10 @@ class TemporaryObservable private _listeners: Array> = []; private _observable: Observable | undefined; - constructor(public name: string, public options?: MetricOptions) {} + constructor( + public name: string, + public options?: MetricOptions, + ) {} addCallback(callback: ObservableCallback): void { if (this._observable) { diff --git a/packages/autometrics/tests/platform.node.test.ts b/packages/autometrics/tests/platform.node.test.ts new file mode 100644 index 00000000..5b4386c1 --- /dev/null +++ b/packages/autometrics/tests/platform.node.test.ts @@ -0,0 +1,16 @@ +import { assertThrows } from "$std/assert/mod.ts"; +import { readClosest } from "../src/platform.node.ts"; + +Deno.test("Node.js platform tests", async (t) => { + // NOTE: Added this test as a quick way to cover the fix from #149 - fix an infinite loop which happens when autometrics is initialized in a node service without a git repository + await t.step( + "readClosest does not loop infinitely on nonexistent file", + () => { + assertThrows( + () => readClosest("nonexistent.file"), + Error, + "Could not read nonexistent.file", + ); + }, + ); +}); diff --git a/packages/parcel-transformer-autometrics/justfile b/packages/parcel-transformer-autometrics/justfile index 9ea21599..1c697a9c 100644 --- a/packages/parcel-transformer-autometrics/justfile +++ b/packages/parcel-transformer-autometrics/justfile @@ -11,4 +11,4 @@ type-check: yarn tsc -p tsconfig.json --noEmit clean: - rm -Rf dist + rm -Rf dist node_modules diff --git a/packages/parcel-transformer-autometrics/src/types.d.ts b/packages/parcel-transformer-autometrics/src/types.d.ts index 9cfbac4f..23f4d7b7 100644 --- a/packages/parcel-transformer-autometrics/src/types.d.ts +++ b/packages/parcel-transformer-autometrics/src/types.d.ts @@ -1,3 +1,10 @@ declare module "@parcel/profiler" { type TraceMeasurement = {}; } + +declare module "@parcel/watcher" { + type Event = {}; + type EventType = {}; + type AsyncSubscription = {}; + type Options = {}; +}