当前位置:网站首页>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
边栏推荐
- An analysis of the CPU surge of an RFID tag management system in.Net
- Detailed explanation of stat function
- MySql的DDL和DML和DQL的基本语法
- Hash - 349. Intersection of two arrays
- L2-011 玩转二叉树
- 安装jmeter
- Best practice | using Tencent cloud AI character recognition to realize enterprise qualification certificate recognition
- DevOps及DevOps常用的工具介绍
- cgo+gSoap+onvif学习总结:9、go和c进行socket通信进行onvif协议处理
- stream流
猜你喜欢
![[deserialization vulnerability-02] principle test and magic method summary of PHP deserialization vulnerability](/img/03/f80c82d009d21a938911a155dddf6b.png)
[deserialization vulnerability-02] principle test and magic method summary of PHP deserialization vulnerability
什么是云原生,云原生技术为什么这么火?

Video playback | how to become an excellent reviewer of international journals in the field of Geoscience and ecology?

Sentinel vs Hystrix 限流对比,到底怎么选?

The art of management - driving software R & D efficiency through leadership

L1-059 敲笨钟
](/img/fd/e12f43e23e6ec76c2b44ce7813e204.png)
运算放大器 —— 快速复苏笔记[贰](应用篇)

【网络空间安全数学基础第9章】有限域

Nodejs ctf 基础

JMeter runtime controller
随机推荐
Ctfshow ThinkPHP topic 1
L1-059 敲笨钟
How to use a third party without obtaining root permission topic: MIUI chapter
Collision, removal and cleaning
L2-011 玩转二叉树
Idea runs the wordcount program (detailed steps)
Stack Title: basic calculator II
容错、熔断的使用与扩展
L1-043 reading room
iMeta观点 | 短读长扩增子测序是否适用于微生物组功能的预测?
Notes on @enableconfigurationproperties
【反序列化漏洞-02】PHP反序列化漏洞原理测试及魔术方法总结
Imeta view | is short reading long amplicon sequencing applicable to the prediction of microbiome function?
Talk about software testing - automated testing framework
L1-043 阅览室
String - 541. Reverse string II
Leetcode 112. path sum
NFT digital collection system construction - app development
Agile? DevOps ?
Leetcode 257. all paths of binary tree