Skip to content
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

Prepare for release 1.0.1 #151

Merged
merged 12 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ 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` commands, you may need to do one or any of the following:

- Remove `node_modules`
- Upgrade `deno`
- Reload all cached deno dependencies (e.g., `find . -type f \( -name "*.ts" \) -exec deno cache --reload {} +`)

### Overview

#### `packages/autometrics`
Expand Down
23 changes: 19 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 @@ -28,7 +31,8 @@ build-parcel-transformer:
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)
build-all: build-parcel-transformer build-typescript-plugin build build-examples

test:
deno test {{test_permissions}} packages/autometrics
Expand Down Expand Up @@ -87,14 +91,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
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 = {};
}
Loading