Skip to content

Commit

Permalink
Prepare for release 1.0.1 (#151)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
brettimus authored Feb 26, 2024
1 parent fd7a386 commit d7875a5
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 17 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions examples/fastify/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __metadata:
version: 6
cacheKey: 8

"@autometrics/[email protected].0, @autometrics/autometrics@workspace:../../dist/autometrics":
"@autometrics/[email protected].1, @autometrics/autometrics@workspace:../../dist/autometrics":
version: 0.0.0-use.local
resolution: "@autometrics/autometrics@workspace:../../dist/autometrics"
dependencies:
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/react-app-experimental/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ __metadata:
languageName: node
linkType: hard

"@autometrics/[email protected].0, @autometrics/autometrics@workspace:../../dist/autometrics":
"@autometrics/[email protected].1, @autometrics/autometrics@workspace:../../dist/autometrics":
version: 0.0.0-use.local
resolution: "@autometrics/autometrics@workspace:../../dist/autometrics"
dependencies:
Expand All @@ -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
Expand All @@ -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
Expand Down
26 changes: 22 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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"

lib_packages := "autometrics exporter-otlp-http exporter-prometheus exporter-prometheus-push-gateway"

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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "autometrics-monorepo",
"packageManager": "[email protected]",
"version": "1.0.0",
"version": "1.0.1",
"workspaces": [
"dist/autometrics",
"dist/exporter-otlp-http",
Expand Down
5 changes: 3 additions & 2 deletions packages/autometrics/src/platform.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions packages/autometrics/src/temporaryMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ class TemporaryCounter<AttributesTypes extends Attributes = Attributes>
> = [];
private _counter: Counter<AttributesTypes> | 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) {
Expand Down Expand Up @@ -321,7 +324,10 @@ class TemporaryHistogram<AttributesTypes extends Attributes = Attributes>
[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) {
Expand Down Expand Up @@ -350,7 +356,10 @@ class TemporaryObservable<AttributesTypes extends Attributes = Attributes>
private _listeners: Array<ObservableCallback<AttributesTypes>> = [];
private _observable: Observable<AttributesTypes> | undefined;

constructor(public name: string, public options?: MetricOptions) {}
constructor(
public name: string,
public options?: MetricOptions,
) {}

addCallback(callback: ObservableCallback<AttributesTypes>): void {
if (this._observable) {
Expand Down
16 changes: 16 additions & 0 deletions packages/autometrics/tests/platform.node.test.ts
Original file line number Diff line number Diff line change
@@ -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",
);
},
);
});
2 changes: 1 addition & 1 deletion packages/parcel-transformer-autometrics/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ type-check:
yarn tsc -p tsconfig.json --noEmit

clean:
rm -Rf dist
rm -Rf dist node_modules
7 changes: 7 additions & 0 deletions packages/parcel-transformer-autometrics/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
declare module "@parcel/profiler" {
type TraceMeasurement = {};
}

declare module "@parcel/watcher" {
type Event = {};
type EventType = {};
type AsyncSubscription = {};
type Options = {};
}

0 comments on commit d7875a5

Please sign in to comment.