autometrics-dev / autometrics-ts

Easily add metrics to your system – and actually understand them using automatically customized Prometheus queries

Home Page:https://autometrics.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Quickstart throws an error in Deno deploy

brettimus opened this issue Β· comments

Environment information

Supabase functions (Deno deploy edge functions) with supabase cli v1.77.9

What happened?

Importing autometrics via import { autometrics } from "https://esm.sh/autometrics@0.5.0"; and wrapping a simple function gave me the following error:

[Info] Autometrics: Initiating a Prometheus Exporter on port: 9464, endpoint: /metrics

[Error] TypeError: (0 , re.createServer) is not a function
    at new r (https://esm.sh/v128/@opentelemetry/exporter-prometheus@0.41.0/esnext/exporter-prometheus.mjs:18:1309)
    at getMetricsProvider (https://esm.sh/v128/@autometrics/autometrics@0.5.0/esnext/autometrics.mjs:4:2276)
    at getMeter (https://esm.sh/v128/@autometrics/autometrics@0.5.0/esnext/autometrics.mjs:4:2387)
    at https://esm.sh/v128/@autometrics/autometrics@0.5.0/esnext/autometrics.mjs:4:3459
    at Server.<anonymous> (file:///home/deno/functions/rabbit/index.ts:15:26)


Expected result

I would expect a friendlier error message instead of a runtime Type error

Thanks for reporting this @brettimus! I need to update the quickstart for Deno-specific instructions. Just to validate that this works can you try importing autometrics with an npm specifier and let me know if that works?

So:

import { autometrics } from "npm:autometrics"

https://deno.land/manual@v1.35.1/node/npm_specifiers#:~:text=Since%20version%201.28%2C%20Deno%20has,by%20importing%20using%20npm%3A%20specifiers.&text=When%20doing%20this%2C%20no%20npm,same%20permissions%20as%20Deno%20applications.

so yeah the issue here is npm specifiers still don't work with Deno deploy (support should be coming this year)

a deno script run with an npm:autometrics import does indeed work

This might be more of a hackday-type kind of suggestion, but we could consider using https://github.com/denoland/dnt instead. Then we'd build the library to be Deno-first, and let them generate the NPM packages for us. It's actually an easier setup altogether, assuming the NPM compatibility doesn't fail us...

oh Deno's dnt looks interesting - I'm tempted πŸ™‚. We use some Node-specific APIs in the libraries that get polyfilled in Deno - I wonder how that will play along with it

If I understand correctly, dnt will polyfill it the other way around, so if you use Deno-specific APIs instead of the Node-specific APIs, it will still make sure it works well as an NPM package too. It might even work out-of-the-box with Node-specific APIs if you use npm: and node: prefixes internally, but then you probably will still run into the same issues with Deno deploy as you have now. But yeah, it might warrant some experimentation :)