获取更多动态,关注公众号:黑客下午茶
rrweb: Session Replays
Sentry 提供了与 rrweb 的 proof-of-concept(概念验证) 集成,该工具包用于记录和重放用户会话。在功能丰富的单页应用程序中诊断复杂的用户行为时,这可能非常有用。
有关可用 hints 的信息,请参阅 hints in JavaScript
回放使用 Attachments.
Configuration
首先,您需要添加 @sentry/rrweb
和 rrweb
软件包:
Copied
npm install --save @sentry/rrweb rrweb
接下来,使用 Sentry SDK 注册集成。这将根据您使用的框架而有所不同:
Copied
import * as Sentry from "@sentry/browser";
import SentryRRWeb from "@sentry/rrweb";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations: [
new SentryRRWeb({
// ...options
}),
],
// ...
});
有关配置的更多信息,请参阅 @sentry/rrweb project on GitHub。
捕获到事件的重播后,您会发现该事件在事件的 “Replay” 部分下的“问题详细信息”中可见。
Sampling
为了满足组织的需求,您可能希望对 replay 进行采样。最简单的方法是在初始化 Sentry SDK 时做出抽样决定。例如,以下是 Sentry 本身如何使用采样来仅捕获员工的样本的方法:
Copied
const hasReplays = getCurrentUser().isStaff;
let integrations = [];
if (hasReplays) {
console.log("[sentry] Instrumenting session with rrweb");
integrations.push(new SentryRRWeb());
}
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations,
});
Sentry.setTag("rrweb.active", hasReplays ? "yes" : "no");
您会注意到我们还设置了 rrweb.active
标记,该标记可帮助我们识别附加了 replay 的事件,因为否则我们将无法找到它们。配置完成后,您将可以在搜索查询中简单地使用 rrweb.active:yes
。
You can edit this page on GitHub.
- Package:
- npm:@sentry/browser
- Version:
- 6.0.2
- Repository:
- https://github.com/getsentry/sentry-javascript