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 all 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
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/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:
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/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:
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": "yarn@3.6.3",
"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 = {};
}
Loading