Sentry 開(kāi)發(fā)者貢獻(xiàn)指南 - JavaScript SDK Minimal
簡(jiǎn)介
嵌入到應(yīng)用程序中時(shí)使用配置 ??client?
?? 的最小 ??Sentry SDK?
??。它允許??庫(kù)作者?
??添加對(duì) ??Sentry SDK?
? 的支持,而無(wú)需捆綁整個(gè) ??SDK?
?? 或依賴于特定平臺(tái)。簡(jiǎn)單來(lái)說(shuō),它是 ??@sentry/node?
?? 或 ??@sentry/browser?
? 等特定于平臺(tái)的 SDK 庫(kù)的公共基礎(chǔ)部分。
Sentry JavaScript SDK Minimal
用法
要使用 ??minimal?
??,您不必初始化 ??SDK?
??。這應(yīng)該由您庫(kù)的用戶處理。而是直接使用 ??@sentry/minimal?
? 的導(dǎo)出函數(shù)添加面包屑或捕獲事件:
import * as Sentry from '@sentry/minimal';
// 為未來(lái)的事件添加面包屑
Sentry.addBreadcrumb({
message: 'My Breadcrumb',
// ...
});
// 捕獲異常、消息或手動(dòng)事件
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
message: 'Manual',
stacktrace: [
// ...
],
});
請(qǐng)注意,雖然嚴(yán)格可行,但不鼓勵(lì)干擾事件上下文。如果由于某種原因您的庫(kù)需要注入上下文信息,請(qǐng)注意這可能會(huì)覆蓋用戶的上下文值:
// 設(shè)置用戶信息、標(biāo)簽和其他附加信息
Sentry.configureScope(scope => {
scope.setExtra('battery', 0.7);
scope.setTag('user_mode', 'admin');
scope.setUser({ id: '4711' });
// scope.clear();
});
測(cè)試用例
PASS test/lib/minimal.test.ts
Minimal
? Clear Scope (1ms)
? returns undefined before binding a client (1ms)
? returns the bound client (1ms)
? Calls function on the client (1ms)
? does not throw an error when pushing different clients (1ms)
? does not throw an error when pushing same clients
? custom carrier (1ms)
? withScope (2ms)
? setExtras (1ms)
? setTags (1ms)
? setExtra (1ms)
? setTag
? setUser (1ms)
? setContext (1ms)
Capture
? Return an event_id (4ms)
? Exception (1ms)
? Exception with explicit scope (1ms)
? Message (1ms)
? Message with explicit scope (1ms)
? Message with custom level (2ms)
? Event (1ms)
configureScope
? User Context (2ms)
? Extra Context (1ms)
? Tags Context (1ms)
? Fingerprint
? Level (1ms)