Skip to content

Commit

Permalink
Merge branch 'main' into Use-delta-temporality-for-React-example
Browse files Browse the repository at this point in the history
  • Loading branch information
brettimus authored Sep 8, 2023
2 parents 227e7e4 + 83be8da commit 13ede13
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 53 deletions.
4 changes: 2 additions & 2 deletions examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"typescript": "^4.9.4"
},
"dependencies": {
"@autometrics/autometrics": "^0.6.0",
"@autometrics/exporter-prometheus": "^0.7.0-beta5",
"@autometrics/autometrics": "^0.7.0-beta10",
"@autometrics/exporter-prometheus": "^0.7.0-beta10",
"express": "^4.18.2",
"node-fetch": "^3.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/faas-experimental/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ init({
//
// However, everything works fine with aggregation gateways.
//
url: "http://localhost:9092/metrics",
url: "http://localhost:8082/metrics",
pushInterval: 0,
});

Expand Down
4 changes: 2 additions & 2 deletions examples/faas-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typescript": "^4.9.4"
},
"dependencies": {
"@autometrics/autometrics": "^0.6.0",
"@autometrics/exporter-prometheus-push-gateway": "^0.7.0-beta5",
"@autometrics/autometrics": "^0.7.0-beta10",
"@autometrics/exporter-prometheus-push-gateway": "^0.7.0-beta10",
"node-fetch": "^3.3.1"
}
}
4 changes: 2 additions & 2 deletions examples/fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"author": "",
"license": "MIT",
"dependencies": {
"@autometrics/autometrics": "^0.6.0",
"@autometrics/exporter-prometheus": "^0.7.0-beta5",
"@autometrics/autometrics": "^0.7.0-beta10",
"@autometrics/exporter-prometheus": "^0.7.0-beta10",
"@prisma/client": "^5.2.0",
"fastify": "^4.13.0"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"start:prod": "node dist/main"
},
"dependencies": {
"@autometrics/autometrics": "^0.7.0-beta5",
"@autometrics/exporter-prometheus": "^0.7.0-beta5",
"@autometrics/autometrics": "^0.7.0-beta10",
"@autometrics/exporter-prometheus": "^0.7.0-beta10",
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/react-app-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"preview": "vite preview"
},
"dependencies": {
"@autometrics/autometrics": "^0.7.0-beta5",
"@autometrics/exporter-otlp-http": "^0.7.0-beta5",
"@autometrics/autometrics": "^0.7.0-beta10",
"@autometrics/exporter-otlp-http": "^0.7.0-beta10",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/autometrics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autometrics/autometrics",
"version": "0.7.0-beta5",
"version": "0.7.0-beta10",
"type": "module",
"description": "Easily add metrics to your system -- and actually understand them using automatically customized Prometheus queries",
"author": "Fiberplane <[email protected]>",
Expand Down
20 changes: 16 additions & 4 deletions packages/autometrics/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@ export function getModulePath(): string | undefined {
const runtime = getRuntime();
if (runtime === "browser") {
rootDir = "";
} else if (runtime === "deno") {
//@ts-ignore
rootDir = Deno.cwd();
} else if (runtime === "node") {
} else if (runtime === "deno" && typeof Deno?.cwd === "function") {
try {
// HACK - Deno Deploy does not necessarily have access to `Deno.cwd`, so we need to handle this case
// Note that in such an event, `Deno.cwd` will still be defined as a function,
// but it will throw an error when invoked
//@ts-ignore
rootDir = Deno.cwd();
} catch (_) {
rootDir = "";
}
} else if (runtime === "node" && typeof process?.cwd === "function") {
// HACK: this assumes the entire app was run from the root directory of the
// project
rootDir = process.cwd();
try {
rootDir = process.cwd();
} catch (_) {
rootDir = "";
}
} else {
rootDir = "";
}
Expand Down
4 changes: 2 additions & 2 deletions packages/exporter-otlp-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autometrics/exporter-otlp-http",
"version": "0.7.0-beta5",
"version": "0.7.0-beta10",
"type": "module",
"description": "Export metrics using OTLP over HTTP/JSON",
"author": "Fiberplane <[email protected]>",
Expand Down Expand Up @@ -32,7 +32,7 @@
"type-check": "tsc -p tsconfig.json"
},
"dependencies": {
"@autometrics/autometrics": "0.7.0-beta5",
"@autometrics/autometrics": "0.7.0-beta10",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.41.0",
"@opentelemetry/sdk-metrics": ">=1.15.0"
Expand Down
4 changes: 3 additions & 1 deletion packages/exporter-otlp-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { registerExporterInternal } from "./registerExporterInternal";

export { AggregationTemporalityPreference };

const MAX_SAFE_INTERVAL = 2 ** 31 - 1;

export type InitOptions = {
/**
* URL of the OpenTelemetry Collector to push metrics to.
Expand Down Expand Up @@ -96,7 +98,7 @@ export function init({

const metricReader = new PeriodicExportingMetricReader({
exporter,
exportIntervalMillis: Number.MAX_SAFE_INTEGER,
exportIntervalMillis: MAX_SAFE_INTERVAL,
exportTimeoutMillis: timeout,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/exporter-prometheus-push-gateway/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autometrics/exporter-prometheus-push-gateway",
"version": "0.7.0-beta5",
"version": "0.7.0-beta10",
"type": "module",
"description": "Export metrics by pushing them to a Prometheus-compatible gateway",
"author": "Fiberplane <[email protected]>",
Expand Down Expand Up @@ -32,7 +32,7 @@
"type-check": "tsc -p tsconfig.json"
},
"dependencies": {
"@autometrics/autometrics": "0.7.0-beta5",
"@autometrics/autometrics": "0.7.0-beta10",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/core": "^1.15.2",
"@opentelemetry/exporter-prometheus": ">=0.35.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/exporter-prometheus-push-gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";

import { PushGatewayExporter } from "./pushGatewayExporter";

const MAX_SAFE_INTERVAL = 2 ** 31 - 1;

export type InitOptions = {
/**
* The full URL (including https://) of the aggregating push gateway for
Expand Down Expand Up @@ -84,7 +86,7 @@ export function init({

const metricReader = new PeriodicExportingMetricReader({
exporter,
exportIntervalMillis: Number.MAX_SAFE_INTEGER,
exportIntervalMillis: MAX_SAFE_INTERVAL,
exportTimeoutMillis: timeout,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export class PushGatewayExporter implements PushMetricExporter {
this._shutdownOnce = new BindOnceFuture(this._shutdown, this);

this.shutdown = this.shutdown.bind(this);
window.addEventListener("unload", this.shutdown);

if (typeof window !== "undefined") {
window.addEventListener("unload", this.shutdown);
}
}

export(
Expand Down Expand Up @@ -98,7 +101,9 @@ export class PushGatewayExporter implements PushMetricExporter {
}

shutdown(): Promise<void> {
window.removeEventListener("unload", this.shutdown);
if (typeof window !== "undefined") {
window.removeEventListener("unload", this.shutdown);
}

return this._shutdownOnce.call();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/exporter-prometheus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autometrics/exporter-prometheus",
"version": "0.7.0-beta5",
"version": "0.7.0-beta10",
"type": "module",
"description": "Export metrics by opening up a Prometheus scrape endpoint",
"author": "Fiberplane <[email protected]>",
Expand Down Expand Up @@ -32,7 +32,7 @@
"type-check": "tsc -p tsconfig.json"
},
"dependencies": {
"@autometrics/autometrics": "0.7.0-beta5",
"@autometrics/autometrics": "0.7.0-beta10",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/exporter-prometheus": ">=0.41.2",
"@opentelemetry/sdk-metrics": ">=1.15.0"
Expand Down
44 changes: 17 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ __metadata:
languageName: node
linkType: hard

"@autometrics/[email protected]beta5, @autometrics/autometrics@^0.7.0-beta5, @autometrics/autometrics@workspace:packages/autometrics":
"@autometrics/[email protected]beta10, @autometrics/autometrics@^0.7.0-beta10, @autometrics/autometrics@workspace:packages/autometrics":
version: 0.0.0-use.local
resolution: "@autometrics/autometrics@workspace:packages/autometrics"
dependencies:
Expand All @@ -78,21 +78,11 @@ __metadata:
languageName: unknown
linkType: soft

"@autometrics/autometrics@npm:^0.6.0":
version: 0.6.0
resolution: "@autometrics/autometrics@npm:0.6.0"
peerDependencies:
"@opentelemetry/exporter-prometheus": ">=0.35.1"
"@opentelemetry/sdk-metrics": ">=1.9.0"
checksum: 79141cfd0997535fa5d9417e08f7f5ddc1afe5406e9f0fd218f8c2216e7cd9ed54713906d3250a8cc9af20dc0d0f54f395dca4b6b7a98298ea1639a66d016df1
languageName: node
linkType: hard

"@autometrics/exporter-otlp-http@^0.7.0-beta5, @autometrics/exporter-otlp-http@workspace:packages/exporter-otlp-http":
"@autometrics/exporter-otlp-http@^0.7.0-beta10, @autometrics/exporter-otlp-http@workspace:packages/exporter-otlp-http":
version: 0.0.0-use.local
resolution: "@autometrics/exporter-otlp-http@workspace:packages/exporter-otlp-http"
dependencies:
"@autometrics/autometrics": 0.7.0-beta5
"@autometrics/autometrics": 0.7.0-beta10
"@opentelemetry/api": ^1.3.0
"@opentelemetry/exporter-metrics-otlp-http": ^0.41.0
"@opentelemetry/sdk-metrics": ">=1.15.0"
Expand All @@ -102,11 +92,11 @@ __metadata:
languageName: unknown
linkType: soft

"@autometrics/exporter-prometheus-push-gateway@^0.7.0-beta5, @autometrics/exporter-prometheus-push-gateway@workspace:packages/exporter-prometheus-push-gateway":
"@autometrics/exporter-prometheus-push-gateway@^0.7.0-beta10, @autometrics/exporter-prometheus-push-gateway@workspace:packages/exporter-prometheus-push-gateway":
version: 0.0.0-use.local
resolution: "@autometrics/exporter-prometheus-push-gateway@workspace:packages/exporter-prometheus-push-gateway"
dependencies:
"@autometrics/autometrics": 0.7.0-beta5
"@autometrics/autometrics": 0.7.0-beta10
"@opentelemetry/api": ^1.3.0
"@opentelemetry/core": ^1.15.2
"@opentelemetry/exporter-prometheus": ">=0.35.1"
Expand All @@ -117,11 +107,11 @@ __metadata:
languageName: unknown
linkType: soft

"@autometrics/exporter-prometheus@^0.7.0-beta5, @autometrics/exporter-prometheus@workspace:packages/exporter-prometheus":
"@autometrics/exporter-prometheus@^0.7.0-beta10, @autometrics/exporter-prometheus@workspace:packages/exporter-prometheus":
version: 0.0.0-use.local
resolution: "@autometrics/exporter-prometheus@workspace:packages/exporter-prometheus"
dependencies:
"@autometrics/autometrics": 0.7.0-beta5
"@autometrics/autometrics": 0.7.0-beta10
"@opentelemetry/api": ^1.3.0
"@opentelemetry/exporter-prometheus": ">=0.41.2"
"@opentelemetry/sdk-metrics": ">=1.15.0"
Expand Down Expand Up @@ -3374,8 +3364,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "express-example@workspace:examples/express"
dependencies:
"@autometrics/autometrics": ^0.6.0
"@autometrics/exporter-prometheus": ^0.7.0-beta5
"@autometrics/autometrics": ^0.7.0-beta10
"@autometrics/exporter-prometheus": ^0.7.0-beta10
"@autometrics/typescript-plugin": ^0.5.4
"@types/express": ^4.17.16
"@types/node": ^18.11.18
Expand Down Expand Up @@ -3439,8 +3429,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "faas-experimental-example@workspace:examples/faas-experimental"
dependencies:
"@autometrics/autometrics": ^0.6.0
"@autometrics/exporter-prometheus-push-gateway": ^0.7.0-beta5
"@autometrics/autometrics": ^0.7.0-beta10
"@autometrics/exporter-prometheus-push-gateway": ^0.7.0-beta10
"@autometrics/typescript-plugin": ^0.5.4
node-fetch: ^3.3.1
tsx: ^3.12.7
Expand Down Expand Up @@ -3537,8 +3527,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "fastify-example@workspace:examples/fastify"
dependencies:
"@autometrics/autometrics": ^0.6.0
"@autometrics/exporter-prometheus": ^0.7.0-beta5
"@autometrics/autometrics": ^0.7.0-beta10
"@autometrics/exporter-prometheus": ^0.7.0-beta10
"@autometrics/typescript-plugin": ^0.5.4
"@prisma/client": ^5.2.0
"@types/node": ^18.13.0
Expand Down Expand Up @@ -5059,8 +5049,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "nestjs-example@workspace:examples/nestjs"
dependencies:
"@autometrics/autometrics": ^0.7.0-beta5
"@autometrics/exporter-prometheus": ^0.7.0-beta5
"@autometrics/autometrics": ^0.7.0-beta10
"@autometrics/exporter-prometheus": ^0.7.0-beta10
"@autometrics/typescript-plugin": ^0.5.4
"@nestjs/cli": ^9.0.0
"@nestjs/common": ^9.0.0
Expand Down Expand Up @@ -5696,8 +5686,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "react-app-example@workspace:examples/react-app-experimental"
dependencies:
"@autometrics/autometrics": ^0.7.0-beta5
"@autometrics/exporter-otlp-http": ^0.7.0-beta5
"@autometrics/autometrics": ^0.7.0-beta10
"@autometrics/exporter-otlp-http": ^0.7.0-beta10
"@autometrics/typescript-plugin": ^0.5.4
"@types/react": ^18.0.27
"@types/react-dom": ^18.0.10
Expand Down

0 comments on commit 13ede13

Please sign in to comment.