honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
485 stars 177 forks source link

No sourcemaps when using Sentry middleware #296

Open flexchar opened 12 months ago

flexchar commented 12 months ago

I've set up Sentry using Hono middleware and errors have no source maps. Is this a bug or is this lack of support due the environment?

Runtime: Cloudflare Workers, deployed using wrangler deploy

I used exact same things from the README: https://github.com/honojs/middleware/tree/main/packages/sentry

This is how it looks in Sentry image

yusukebe commented 12 months ago

Hi @flexchar

Currently, Hono does not provide source maps, which likely means that Sentry Middleware does not support it.

Related to https://github.com/honojs/hono/issues/1712

riderx commented 7 months ago

From toucan-js exemple i saw we can generate the sourceMap with wrangler publish --dry-run --outdir=dist then I uploaded with :

bun x @sentry/cli releases new "[VERSION]" --finalize --org [ORG] -p  [PROJECT]
bun x @sentry/cli releases files "[VERSION]" upload-sourcemaps ./dist --org [ORG] -p  [PROJECT]

And add in your sentry object, the release:

const app = new Hono()

app.use('*', sentry({
  release: `[VERSION]`
}))
flexchar commented 6 months ago

Thanks for the example, @riderx Martin!

It inspired my to find out about the defined variables to create even prettier solution but unfortunately they are not working. I am currently blocked by this issue https://github.com/cloudflare/workers-sdk/issues/5720.

Excited to have this as an official part of Hono as soon as the blocking issue is fixed. :)

FraBle commented 2 months ago

@flexchar Are the any updates on your more elegant solution?

flexchar commented 2 months ago

Hey Frank, to be honest I didn't invent something much more. I have these scripts in my package.json:

{
  "scripts": {
    "dev": "wrangler dev src/routes.ts --define \"GIT_COMMIT:'development'\" --test-scheduled",
    "deploy": "wrangler deploy --define \"GIT_COMMIT:'$(git rev-parse HEAD)'\" --outdir dist --minify src/routes.ts && bun run deploy-sentry",
    "deploy-sentry": "sentry-cli sourcemaps upload --release=$(git rev-parse HEAD) --org SENTRY_ORGANIZATOIN -p SENTRY_PROJECT ./dist",
  },

and then I still have this beautiful snippet in my routes.ts :D

import { sentry } from '@hono/sentry';
import { Hono } from 'hono';

// https://hono.dev/
const app = new Hono<{ Bindings: Bindings }>();

// ToDo: implement sentry source maps
// Solution example: https://github.com/honojs/middleware/issues/296#issuecomment-2071212103
// Command example: https://github.com/robertcepa/toucan-js/blob/master/examples/wrangler-basic/package.json
// Defined variables issue: https://github.com/cloudflare/workers-sdk/issues/5720#issuecomment-2090079286
app.use('*', (c, next) =>
    sentry({
        enabled: !c.env.IS_DEV,
        environment: c.env.ENVIRONMENT,
        debug: c.env.ENVIRONMENT === 'development',
        release: GIT_COMMIT ?? 'unknown',
    })(c, next),
);

Hope that helps, it does provide me source maps in Sentry. @FraBle

FraBle commented 2 months ago

@flexchar Thanks for sharing 🙌