Skip to content

Commit

Permalink
Add wrapper for performance.now and bump packages to beta test vercel…
Browse files Browse the repository at this point in the history
… edge function support
  • Loading branch information
brettimus committed Oct 3, 2023
1 parent e17a6a6 commit 6543783
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"release-all:beta": "yarn workspaces foreach -t --verbose --exclude=\"*-example\" --exclude=\"*-monorepo\" npm publish --tag beta",
"release-lib": "yarn workspaces foreach -t --verbose --include=\"@autometrics/autometrics\" --include=\"@autometrics/exporter-*\" npm publish",
"release-lib:beta": "yarn workspaces foreach -t --verbose --include=\"@autometrics/autometrics\" --include=\"@autometrics/exporter-*\" npm publish --tag beta",
"release-vercel:beta": "yarn workspaces foreach -t --verbose --include=\"@autometrics/autometrics\" --include=\"@autometrics/exporter-prometheus-push-gateway\" npm publish --tag beta",
"type-check": "yarn workspaces foreach -p --verbose run type-check",
"build:main": "yarn workspaces foreach -pt --verbose --include=\"@autometrics/autometrics\" --include=\"@autometrics/exporter-*\" run build",
"dev:main": "yarn workspaces foreach -pt --verbose --include=\"@autometrics/autometrics\" --include=\"@autometrics/exporter-*\" run dev",
Expand All @@ -40,4 +41,4 @@
"typescript": "^5.0.4",
"vitest": "^0.34.3"
}
}
}
4 changes: 2 additions & 2 deletions 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",
"version": "0.7.2-beta.0",
"type": "module",
"description": "Easily add metrics to your system -- and actually understand them using automatically customized Prometheus queries",
"author": "Fiberplane <info@fiberplane.com>",
Expand Down Expand Up @@ -44,4 +44,4 @@
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.0.4"
}
}
}
21 changes: 21 additions & 0 deletions packages/autometrics/src/performance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

const START = Date.now();

/**
* Utility function for using the performance.now() function if it exists, otherwise
* falls back to Date.now() - START, which has less precision but shouldn't matter for us.
*
* @note - This is required for compatibility with the Vercel Edge Function Runtime
*/
export function now() {
if (hasPerformanceNow()) {
return performance.now();
}


return Date.now() - START;
}

function hasPerformanceNow() {
return typeof performance !== "undefined" && "now" in performance && typeof performance.now === "function";
}
1 change: 1 addition & 0 deletions packages/autometrics/src/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
isObject,
isPromise,
} from "./utils";
import * as performance from "./performance";

let asyncLocalStorage: ALSInstance | undefined;
if (typeof window === "undefined") {
Expand Down
6 changes: 3 additions & 3 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.1",
"version": "0.7.2-beta.0",
"type": "module",
"description": "Export metrics by pushing them to a Prometheus-compatible gateway",
"author": "Fiberplane <info@fiberplane.com>",
Expand Down Expand Up @@ -32,7 +32,7 @@
"type-check": "tsc -p tsconfig.json"
},
"dependencies": {
"@autometrics/autometrics": "^0.7.0",
"@autometrics/autometrics": "^0.7.2-beta.0",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/core": "^1.15.2",
"@opentelemetry/exporter-prometheus": ">=0.35.1",
Expand All @@ -43,4 +43,4 @@
"tsup": "^7.2.0",
"typescript": "^5.0.4"
}
}
}

0 comments on commit 6543783

Please sign in to comment.