With a Bundler for Hono
Learn how to run your app with Sentry using a bundler plugin, without the --import flag.
Are you unsure if you should use this installation method? Review our installation methods.
If you build your server with a bundler, you can instrument your dependencies at build time with the Sentry bundler plugin instead of loading Sentry with the --import flag. Because the instrumentation is baked into your bundle, a plain top-level import of your instrument file is enough, and you can start your app with a regular node command, without the --import flag.
Use this method if you can't pass a command line flag to the Node.js binary, for example when your start command is fixed by your platform or process manager.
Create a file named instrument.(js|mjs) in the root directory of your project that initializes Sentry:
instrument.jsconst Sentry = require("@sentry/node");
// ___PRODUCT_OPTION_START___ profiling
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
// ___PRODUCT_OPTION_END___ profiling
// Ensure to call this before requiring any other modules!
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ profiling
// Add our Profiling integration
nodeProfilingIntegration(),
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/hono/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
// Enable profiling for a percentage of sessions
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#profileSessionSampleRate
profileSessionSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ profiling
});
const Sentry = require("@sentry/node");
// ___PRODUCT_OPTION_START___ profiling
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
// ___PRODUCT_OPTION_END___ profiling
// Ensure to call this before requiring any other modules!
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ profiling
// Add our Profiling integration
nodeProfilingIntegration(),
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/hono/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
// Enable profiling for a percentage of sessions
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#profileSessionSampleRate
profileSessionSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ profiling
});
import * as Sentry from "@sentry/node";
// ___PRODUCT_OPTION_START___ profiling
import { nodeProfilingIntegration } from "@sentry/profiling-node";
// ___PRODUCT_OPTION_END___ profiling
// Ensure to call this before importing any other modules!
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ profiling
// Add our Profiling integration
nodeProfilingIntegration(),
// ___PRODUCT_OPTION_END___ profiling
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/hono/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
// Enable profiling for a percentage of sessions
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#profileSessionSampleRate
profileSessionSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ profiling
});
Add the Sentry plugin for your bundler to your build configuration. The plugin instruments your dependencies at build time, so the SDK no longer depends on Sentry.init() running before your other imports.
vite.config.mjsimport { sentryVitePlugin } from "@sentry/node/vite";
export default {
plugins: [sentryVitePlugin()],
};
import { sentryVitePlugin } from "@sentry/node/vite";
export default {
plugins: [sentryVitePlugin()],
};
import { sentryRollupPlugin } from "@sentry/node/rollup";
export default {
plugins: [sentryRollupPlugin()],
};
import { sentryWebpackPlugin } from "@sentry/node/webpack";
export default {
plugins: [sentryWebpackPlugin()],
};
import { sentryEsbuildPlugin } from "@sentry/node/esbuild";
await esbuild.build({
plugins: [sentryEsbuildPlugin()],
});
Import instrument.(js|mjs) at the very top of your application's entry point, before any other imports:
app.mjs// Import this first!
import "./instrument.mjs";
// Now import other modules
import express from "express";
// Your application code goes here
// Import this first!
import "./instrument.mjs";
// Now import other modules
import express from "express";
// Your application code goes here
Start your application as usual. No --import flag is required, because the instrumentation is already part of your bundle:
node app.mjs
node app.mjs
If you can't use a bundler, review our other installation methods for alternatives that don't rely on the --import flag.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").