inngest / inngest-js

The developer platform for easily building reliable workflows with zero infrastructure for TypeScript & JavaScript
https://www.inngest.com/
GNU General Public License v3.0
414 stars 41 forks source link

Unable to use Inngest handlers alongside Sentry integration middleware #436

Closed spastorelli closed 9 months ago

spastorelli commented 9 months ago

Description

When using Inngest serve handler in an express app where Sentry integration middleware is also used, Sentry middleware is throwing the following error upon starting the app:

Error: Express middleware takes 2-4 arguments. Got: 0
    at wrap (/home/runner/InngestWithSentryRepro/node_modules/@sentry-internal/tracing/cjs/node/integrations/express.js:133:13)
    at /home/runner/InngestWithSentryRepro/node_modules/@sentry-internal/tracing/cjs/node/integrations/express.js:151:14
    at Array.map (<anonymous>)
    at wrapMiddlewareArgs (/home/runner/InngestWithSentryRepro/node_modules/@sentry-internal/tracing/cjs/node/integrations/express.js:149:15)
    at router.<computed> [as use] (/home/runner/InngestWithSentryRepro/node_modules/@sentry-internal/tracing/cjs/node/integrations/express.js:174:43)
    at file:///home/runner/InngestWithSentryRepro/index.js:39:5

Looking a bit into it, it looks to be a similar issue as described here: https://github.com/getsentry/sentry-javascript/issues/3284#issuecomment-838405407

I've tried to implement a custom Inngest handler (i.e InngestCommHandler) and trying to use a similar approach described here but can't get it to work.

Do you have any suggestions on how to get around this issue?

To Reproduce Steps to reproduce the behavior:

  1. Create an express with Sentry & Inngest middlewares, e.g:
    
    import express from "express";

import Sentry from "@sentry/node"; import SentryTracing from "@sentry/tracing";

import { Inngest } from "inngest"; import { serve } from "inngest/express";

const inngestClient = new Inngest({ id: "test-sync-application", });

const importFunction = inngestClient.createFunction( { id: "sync-import" }, { event: "sync/import" }, async ({ event, step, runId }) => { console.log("running"); }, );

const app = express(); app.use(express.json());

// Sentry integration middlewares Sentry.init({ dsn: "http://test@test.com/123", debug: true, integrations: [ new Sentry.Integrations.Http({ tracing: true }), new SentryTracing.Integrations.Express({ app }), ], tracesSampleRate: 1, });

app.use(Sentry.Handlers.requestHandler()); app.use(Sentry.Handlers.tracingHandler());

// Inngest middleware app.use( "/api/inngest", serve({ client: inngestClient, functions: [importFunction] }), );

app.listen(3000, () => { console.log("Express server initialized"); });


2. Run the above express app
3. **Observation:** The sentry middleware is throwing the following error:

Error: Express middleware takes 2-4 arguments. Got: 0 at wrap (/home/runner/InngestWithSentryRepro/node_modules/@sentry-internal/tracing/cjs/node/integrations/express.js:133:13)



**Expected behavior**

Expected both middleware to be used in the same express app.

**Code snippets / Logs / Screenshots**

**Repl.it:** https://replit.com/@spsgitbook/InngestWithSentryRepro#index.js

**Additional context**
Add any other context about the problem here.
jpwilliams commented 9 months ago

Thanks for reporting, @spastorelli!

This should be fixed in #440 🙂

Thanks loads for the repro - makes solving these super easy. ❤️

jpwilliams commented 9 months ago

@spastorelli Fixed in inngest@3.7.4 🙂

spastorelli commented 9 months ago

Thanks @jpwilliams for the quick turnaround & resolution.