设置跟踪
了解如何在应用程序中启用跟踪。
一旦你为 Sentry SDK 定义了 tracesSampleRate
,跟踪将被启用。这将自动插桩和监控应用程序的性能。
如果你在高吞吐量环境中采用跟踪,建议在部署前进行测试,以确保服务的性能特性符合预期。
instrument.js
Copied
const Sentry = require("@sentry/node");
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
// Ensure to call this before requiring any other modules!
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations: [
// Add our Profiling integration
nodeProfilingIntegration(),
],
// Add Tracing by setting tracesSampleRate
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
// Set sampling rate for profiling
// This is relative to tracesSampleRate
profilesSampleRate: 1.0,
});
参阅 自动插桩 了解 SDK 自动插桩的内容。
你还可以手动启动跨度以插桩代码的特定部分。这在你想要测量特定操作或函数的性能时非常有用。
参阅 自定义插桩 了解如何手动启动跨度。