Skip to content

Add docs and wizard to configure sourcemaps for cloudflare + wrangler #14841

Closed

Description

@bhanuka-yd

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/cloudflare

SDK Version

8.47.0

Framework Version

wrangler: 3.99.0

Link to Sentry event

https://hyperbyte.sentry.io/issues/15388878/events/6faf01ca3f04449081bf9dab43025a33/

Reproduction Example/SDK Setup

index.js

export default Sentry.withSentry(
	(env: Env) => ({
		dsn: env.SENTRY_DSN,
		// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
		tracesSampleRate: env.SENTRY_TRACES_SAMPLE_RATE,
		environment: 'production'
	}),
	{
		async fetch(request: Request, env, ctx): Promise<Response> {

			const configParse = configSchema.safeParse(env);
			if (!configParse.success) {
				return configErr(configParse.error, env);
			} else {
				env = configParse.data;
			}

			globalThis.env = env;
			// globalThis.prisma = prismaFactory(env.DATABASE_URL);
			globalThis.db = getDB(env.DATABASE_URL);

			return fetchRequestHandler({
				endpoint: '/trpc',
				req: request,
				router: appRouter,
				createContext
			});
		}
	} satisfies ExportedHandler<Env>
);

error-generating-file.js

Sentry.captureException(result.error);

rollup.config.js

    import resolve from '@rollup/plugin-node-resolve';
    import commonjs from '@rollup/plugin-commonjs';
    import typescript from '@rollup/plugin-typescript';
    import terser from '@rollup/plugin-terser';
    import json from '@rollup/plugin-json';
    import { sentryRollupPlugin } from '@sentry/rollup-plugin';
    
    export default {
    	input: 'src/index.ts',  // Path to your main entry file,
    	output: {
    		file: 'dist/worker.js',  // Output path for your bundled worker
    		format: 'es',  // Cloudflare Workers support ES Modules
    		sourcemap: true,
    		inlineDynamicImports: true
    	},
    	plugins: [
    		resolve(),  // Resolve node modules
    		commonjs(),
    		json(),
    		typescript({
    			tsconfig: './tsconfig.json'
    		}),
    		terser(),   // Minify the output (optional)
    		sentryRollupPlugin({
    			authToken: process.env.SENTRY_AUTH_TOKEN,
    			org: '------',
    			project: '--------'
    		})
    
    	]
    };

wrangler.toml

upload_source_maps = true

[build]
#custom build command
command = "npm run build"

Steps to Reproduce

  1. Add sentry @sentry/cloudflare
  2. Setup init
  3. Test using Sentry.captureException()
  4. Setup rollup

Expected Result

  • Compiled code includes e._sentryDebugIds=e._sentryDebugIds||{}
  • Issue reported to sentry
  • Issue Stack-trace visible
  • Issue Stack-trace un-minified
  • event json does not include debug_meta

Actual Result

  • Compiled code includes e._sentryDebugIds=e._sentryDebugIds||{}
  • Issue reported to sentry
  • Issue Stack-trace visible
  • Issue Stack-trace un-minified
  • event json does not include debug_meta

shows that
Image

i have checked the event json and it does not contain debug_meta

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Dec 27, 2024
  2. andreiborza commented on Dec 27, 2024

    @andreiborza
    Member

    Hi @bhanuka-yd, thanks for writing in.

    Could you please set debug: true in the rollup plugin and paste some build logs?

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Dec 27, 2024
  4. bhanuka-yd commented on Dec 27, 2024

    @bhanuka-yd
    Author

    Hi @andreiborza, sure here's the output.

    rollup -c rollup.config.mjs

    [sentry-rollup-plugin] Info: Using environment variables configured in ".env.sentry-build-plugin".

    src/index.ts → dist/worker.js...
    [sentry-rollup-plugin] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set options.telemetry to false.
    [sentry-rollup-plugin] Debug: No sourcemaps.assets option provided, falling back to uploading detected build artifacts.

    Found 2 files
    Analyzing 2 sources
    Analyzing completed in 0.032s
    Adding source map references
    Bundling completed in 0.19s
    Bundled 2 files for upload
    Bundle ID: 759fb507-c679-513f-8436-8fcd080c42ea
    Optimizing completed in 0.006s
    Uploading completed in 4.478s
    Uploaded files to Sentry
    Processing completed in 1.459s
    File upload complete (processing pending on server)
    Organization: ------------
    Project: ---------------
    Release: 69e8d6aa31b6a806ea9388d59583069411fbf4d3
    Dist: None
    Upload type: artifact bundle

    Source Map Upload Report
    Scripts
    ~/167414e4-08a0-4d95-a51f-9efdaa05e16a-0.js (sourcemap at worker.js.map, debug id 167414e4-08a0-4d95-a51f-9efdaa05e16a)
    Source Maps
    ~/167414e4-08a0-4d95-a51f-9efdaa05e16a-0.js.map (debug id 167414e4-08a0-4d95-a51f-9efdaa05e16a)
    [sentry-rollup-plugin] Info: Successfully uploaded source maps to Sentry
    (!) Circular dependencies
    node_modules/@smithy/util-stream/dist-es/blob/Uint8ArrayBlobAdapter.js -> node_modules/@smithy/util-stream/dist-es/blob/transforms.js -> node_modules/@smithy/util-stream/dist-es/blob/Uint8ArrayBlobAdapter.js
    node_modules/@aws-crypto/crc32c/build/module/index.js -> node_modules/@aws-crypto/crc32c/build/module/aws_crc32c.js -> node_modules/@aws-crypto/crc32c/build/module/index.js
    node_modules/@aws-crypto/crc32/build/module/index.js -> node_modules/@aws-crypto/crc32/build/module/aws_crc32.js -> node_modules/@aws-crypto/crc32/build/module/index.js
    ...and 7 more
    created dist/worker.js in 23.1s
    Total Upload: 1716.87 KiB / gzip: 320.36 KiB
    Worker Startup Time: 82 ms

  5. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Dec 27, 2024
  6. Lms24 commented on Jan 2, 2025

    @Lms24
    Member

    Hi @bhanuka-yd, I didn't find anything yet that would prohibit debug ids from being applied to error events. Before we dig into this deeper: Can you confirm that the files where debug ids were injected correctly are the exact same files that get deployed to cloudflare? The debug_meta field in the event JSON can only be populated, if the deployed files contain the e._sentryDebugIds snippet.

    If this is the case, we need to dive deeper into SDK internals to understand what's going on. If you can, please provide a minimal reproduction, for example in the form of a GH repo, zip file or whatever else works for you.

    If you can't, please console.log some things:

    • in beforeSend, please log out event and event.exception.values so that we can check what the SDK sends exactly. Sometimes, the event JSON in the Sentry UI already contains slight changes.
    • in beforeSend, please also log out globalThis._sentryDebugIds so that we can check if the SDK could even pick up debug ids.

    Side-note: I did find a bug in our debug id application logic but it's rather an edge case, where debug ids were not correctly applied to events containing multiple errors. However I don't think this has anything to do with your problem. Anyway, the found bug will be fixed via #14881.

  7. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jan 2, 2025
  8. moved this to Waiting for: Community in GitHub Issues with 👀 3on Jan 2, 2025
  9. 23 remaining items

  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jan 24, 2025
  11. removed theissue type on Mar 3, 2025
  12. added theissue type on Mar 3, 2025
  13. changed the title [-]@sentry/cloudflare not sending debugIds ?[/-] [+]Add docs and wizard to configure sourcemaps for cloudflare + wrangler[/+] on Mar 3, 2025
  14. AbhiPrasad commented on Jun 10, 2025

    @AbhiPrasad
    Contributor

    should be done with getsentry/sentry-wizard#824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions