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

Instrument Express with Deno #15048

Open
3 tasks done
NideoTV opened this issue Jan 17, 2025 · 1 comment
Open
3 tasks done

Instrument Express with Deno #15048

NideoTV opened this issue Jan 17, 2025 · 1 comment
Labels
Package: deno Issues related to the Sentry Deno SDK

Comments

@NideoTV
Copy link

NideoTV commented Jan 17, 2025

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/deno

SDK Version

8.48.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

// instument.js

import * as Sentry from "npm:@sentry/deno";

Sentry.init({
    debug: true,
    dsn: "...",
    profilesSampleRate: 1.0,
    tracesSampleRate: 1.0,
});

// main.js

import './instrument.js';
import app from './express.js';

// express.js

import * as Sentry from "npm:@sentry/deno";
import express from "npm:express";
const app = express();
Sentry.setupExpressErrorHandler(app);

Steps to Reproduce

deno run -A main.js

Expected Result

I expected Express to be instrumented, or the Sentry Express documentation to specify that "Deno is not supported".

Also we can't use the ESM installation in Deno since "--import" is not available.

Alternate error : Using Sentry/Node package in Deno

I also tried to use the sentry/node package in Deno (replaced every "sentry/deno by sentry/node) and got the same result :

% deno run -A main.js
Sentry Logger [warn]: Failed to register ESM hook TypeError: moduleModule.register is not a function
    at maybeInitializeEsmLoader (file:///Users/nicolasbonzom/Library/Caches/deno/npm/registry.npmjs.org/@sentry/node/8.48.0/build/esm/sdk/initOtel.js:56:22)
    at _init (file:///Users/nicolasbonzom/Library/Caches/deno/npm/registry.npmjs.org/@sentry/node/8.48.0/build/esm/sdk/index.js:111:5)
    at Module.init (file:///Users/nicolasbonzom/Library/Caches/deno/npm/registry.npmjs.org/@sentry/node/8.48.0/build/esm/sdk/index.js:79:10)
    at file:///Users/nicolasbonzom/Documents/expertnet/dev/jobgate-server/instrument.js:3:8
Sentry Logger [log]: Initializing Sentry: process: 89576, thread: main.
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: RequestData
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: NodeFetch
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: LocalVariablesAsync
Sentry Logger [log]: Integration installed: Context
Sentry Logger [log]: Integration installed: ProcessAndThreadBreadcrumbs
Sentry Logger [log]: Integration installed: Express
Sentry Logger [log]: Integration installed: Fastify
Sentry Logger [log]: Integration installed: Graphql
Sentry Logger [log]: Integration installed: Mongo
Sentry Logger [log]: Integration installed: Mongoose
Sentry Logger [log]: Integration installed: Mysql
Sentry Logger [log]: Integration installed: Mysql2
Sentry Logger [log]: Integration installed: Redis
Sentry Logger [log]: Integration installed: Postgres
Sentry Logger [log]: Integration installed: Nest
Sentry Logger [log]: Integration installed: Hapi
Sentry Logger [log]: Integration installed: Koa
Sentry Logger [log]: Integration installed: Connect
Sentry Logger [log]: Integration installed: Tedious
Sentry Logger [log]: Integration installed: GenericPool
Sentry Logger [log]: Integration installed: Kafka
Sentry Logger [log]: Integration installed: Amqplib
Sentry Logger [log]: Integration installed: LruMemoizer
Sentry Logger [log]: Integration installed: vercelAI
Sentry Logger [log]: Running in ESM mode.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for diag v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for trace v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for context v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: "http" }
Sentry Logger [debug]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: "http" }
[Sentry] express is not instrumented. Please make sure to initialize Sentry in a separate file that you `--import` when running node, see: https://docs.sentry.io/platforms/javascript/guides/express/install/esm/.

Actual Result

Logs using Sentry/Deno Package

% deno run -A main.js
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: Dedupe
Sentry Logger [log]: Integration installed: Breadcrumbs
Sentry Logger [log]: Integration installed: DenoContext
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: NormalizePaths
Sentry Logger [log]: Integration installed: GlobalHandlers
error: Uncaught (in promise) TypeError: Sentry.setupExpressErrorHandler is not a function
Sentry.setupExpressErrorHandler(app);
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 17, 2025
@github-actions github-actions bot added the Package: deno Issues related to the Sentry Deno SDK label Jan 17, 2025
@andreiborza
Copy link
Member

andreiborza commented Jan 20, 2025

Hey @NideoTV, thanks for writing in.

If you are using express, I'd recommend going with the @sentry/node package, our deno SDK does currently not export any helpers for express.

I set up this locally:

import './instrument.js'
import * as Sentry from 'npm:@sentry/node'
import express from "npm:express";

const app = express();

Sentry.setupExpressErrorHandler(app);

app.get('/foo', async (req, res) => {
    res.send('Ok')
});

app.listen(3000, () => {
    console.log(`API running @ http://localhost:3000`);
});

and while I am getting the same warning about failing to register the ESM hook, I am getting proper logs:

Sentry Logger [log]: Running in ESM mode.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for diag v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for trace v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for context v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: "http" }
Sentry Logger [debug]: @sentry/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: "http" }
Sentry Logger [debug]: @opentelemetry/instrumentation-express Applying instrumentation patch for module on require hook {
  module: "express",
  version: "4.21.2",
  baseDir: "<redacted>"
}

and I am seeing traces

Image

Could you provide a reproduction repo please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: deno Issues related to the Sentry Deno SDK
Projects
Status: No status
Development

No branches or pull requests

2 participants