当前位置:网站首页>Source code analysis sentry user behavior record implementation process
Source code analysis sentry user behavior record implementation process
2022-07-24 11:45:00 【InfoQ】
Preface

The source code to achieve
initinitinitAndBindgetCurrentHub().bindClient()Hub.prototype.bindClient = function (client) {
// Get the last
var top = this.getStackTop();
// hold new BrowerClient() example Bound to the top On
top.client = client;
if (client && client.setupIntegrations) {
client.setupIntegrations();
}
};
client.setupIntegrations()@sentry/core/integration.jsexport function setupIntegrations(options) {
var integrations = {};
getIntegrationsToSetup(options).forEach(function (integration) {
integrations[integration.name] = integration;
setupIntegration(integration);
});
return integrations;
}
setupIntegrationsetupOncesetupOnceexport function setupIntegration(integration) {
if (installedIntegrations.indexOf(integration.name) !== -1) {
return;
}
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
installedIntegrations.push(integration.name);
logger.log("Integration installed: " + integration.name);
}
@sentry/broswer/integrations/breadcrumbs.jssetupOnceBreadcrumbs.prototype.setupOnce = function () {
var _this = this;
if (this._options.console) {
addInstrumentationHandler({
callback: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
_this._consoleBreadcrumb.apply(_this, __spread(args));
},
type: 'console',
});
}
if (this._options.dom) {
addInstrumentationHandler({
...,
type: 'dom',
});
}
if (this._options.xhr) {
addInstrumentationHandler({
..,
type: 'xhr',
});
}
if (this._options.fetch) {
addInstrumentationHandler({
...,
type: 'fetch',
});
}
if (this._options.history) {
addInstrumentationHandler({
...,
type: 'history',
});
}
};
addInstrumentationHandler@sentry/utils/instrument.jsinstrument
function instrument(type) {
if (instrumented[type]) {
return;
}
instrumented[type] = true;
switch (type) {
case 'console':
instrumentConsole();
break;
case 'dom':
instrumentDOM();
break;
case 'xhr':
instrumentXHR();
break;
case 'fetch':
instrumentFetch();
break;
case 'history':
instrumentHistory();
break;
case 'error':
instrumentError();
break;
case 'unhandledrejection':
instrumentUnhandledRejection();
break;
default:
logger.warn('unknown instrumentation type:', type);
}
}
getCurrentHub().addBreadcrumbBreadcrumbs.prototype._consoleBreadcrumb = function (handlerData) {
var breadcrumb = {
category: 'console',
data: {
arguments: handlerData.args,
logger: 'console',
},
level: Severity.fromString(handlerData.level),
message: safeJoin(handlerData.args, ' '),
};
if (handlerData.level === 'assert') {
if (handlerData.args[0] === false) {
breadcrumb.message = "Assertion failed: " + (safeJoin(handlerData.args.slice(1), ' ') || 'console.assert');
breadcrumb.data.arguments = handlerData.args.slice(1);
}
else {
// Don't capture a breadcrumb for passed assertions
return;
}
}
getCurrentHub().addBreadcrumb(breadcrumb, {
input: handlerData.args,
level: handlerData.level,
});
}
getCurrentHub().addBreadcrumb@sentry/hub/scope.jsthis._breadcrumbs(Scope)Scope.prototype.addBreadcrumb = function (breadcrumb, maxBreadcrumbs) {
var mergedBreadcrumb = __assign({ timestamp: dateTimestampInSeconds() }, breadcrumb);
this._breadcrumbs =
maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
? __spread(this._breadcrumbs, [mergedBreadcrumb]).slice(-maxBreadcrumbs)
: __spread(this._breadcrumbs, [mergedBreadcrumb]);
this._notifyScopeListeners();
return this;
};
__SENTRY__hub_breadcrumbs
this.getStackTop()scopethis.getStackTop().scope_breadcrumbs_user_tags_extraHub.prototype._invokeClient = function (method) {
var _a;
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
var top = this.getStackTop();
if (top && top.client && top.client[method]) {
(_a = top.client)[method].apply(_a, __spread(args, [top.scope]));
}
};

Overall flow chart

Last
边栏推荐
- L1-064 估值一亿的AI核心代码
- Hash - 15. Sum of three numbers
- Svn server and client installation (Chinese package) and simple use
- Semaphore details
- 视频回放 | 如何成为一名优秀的地学和生态学领域的国际期刊审稿人?
- Use of getchar
- 使用Prometheus+Grafana实时监控服务器性能
- Grep actually uses ps/netstat/sort
- Jackson parsing JSON detailed tutorial
- String - 541. Reverse string II
猜你喜欢

一周精彩内容分享(第13期)

GCC的基本用法

tcp 服务端接收数据处理思路梳理,以及select: Invalid argument报错 笔记
![Operational amplifier - Notes on rapid recovery [II] (application)](/img/fd/e12f43e23e6ec76c2b44ce7813e204.png)
Operational amplifier - Notes on rapid recovery [II] (application)

cgo+gSoap+onvif学习总结:9、go和c进行socket通信进行onvif协议处理

容错、熔断的使用与扩展
![MOS tube - Notes on rapid recovery application (I) [principle]](/img/a1/8427c9b1d0ea0cecce820816510045.png)
MOS tube - Notes on rapid recovery application (I) [principle]

Share the typora tool

HCIP OSPF接口网络类型实验 第四天

使用Prometheus+Grafana实时监控服务器性能
随机推荐
Agile? DevOps ?
cgo+gSoap+onvif学习总结:9、go和c进行socket通信进行onvif协议处理
Is there any charge for PDF processing? impossible!
Code of login page
L1-059 ring stupid bell
DevOps及DevOps常用的工具介绍
Paging query of employee information of black maredge takeout
6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
【网络空间安全数学基础第3章】同余
Shengxin weekly issue 37
SSH跨平台终端工具tabby推荐
JMeter if controller
哈希——242.有效的字母异位词
Repeated calls, messages, idempotent schemes, full collation
Nodejs ctf 基础
MySQL creates partition tables and automatically partitions them by day
L1-059 敲笨钟
[TA frost wolf umay - "hundred people plan] Figure 3.3 surface subdivision and geometric shader large-scale grass rendering
【网络空间安全数学基础第9章】有限域
L2-011 play with binary tree