Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ued2345/laserbeak

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ued2345/laserbeak - npm Package Compare versions

Comparing version 0.4.0 to 0.20.0-alpha.1

src/plugin/export-global.js

10

package.json
{
"name": "@ued2345/laserbeak",
"version": "0.4.0",
"version": "0.20.0-alpha.1",
"description": "JS SDK for logging systems",

@@ -8,4 +8,4 @@ "main": "src/index.js",

"scripts": {
"build": "npx uglifyjs ./src/seed/index.js -o ./dist/logger-seed.min.js -c -m --ie8 --timings --comments '/^!/'",
"lint": "eslint ./**/*.js"
"build": "uglifyjs ./src/seed/index.js -o ./dist/logger-seed.min.js -c -m --ie8 --timings --comments '/^!/'",
"lint": "eslint \"./**/*.js\""
},

@@ -27,6 +27,6 @@ "keywords": [

"devDependencies": {
"@ued2345/eslint-config": "^0.4.1",
"eslint": "^6.7.2",
"@ued2345/eslint-config": "^0.4.3",
"eslint": "^6.8.0",
"uglify-js": "^3.8.0"
}
}

@@ -1,11 +0,9 @@

import * as SentrySDK from '@sentry/browser'
import * as SentryIntegrations from '@sentry/integrations'
import { exportGlobal } from './plugin/export-global'
import { appConfig, log as _log, sample } from './util'
export { initSentry, Sentry } from './plugin/sentry'
export { log } from './plugin/log'
export { initResError } from './plugin/resource-error'
export { install } from './plugin/vue-plugin'
const appConfig = {}
export const Sentry = SentrySDK
export function init({

@@ -19,7 +17,7 @@ debug = false,

if (!appName) {
log('[Logger] [Init] failed: `appName` is missing!')
_log('[Logger] [Init] failed: `appName` is missing!')
return
}
if (!(version || version === 0)) {
log('[Logger] [Init] failed: `version` is missing!')
_log('[Logger] [Init] failed: `version` is missing!')
return

@@ -36,103 +34,14 @@ }

if (!appConfig._isSampled) {
log('[Logger] current user is **NOT** sampled.')
_log('[Logger] current user is **NOT** sampled.')
} else {
log('[Logger] current user is sampled.')
_log('[Logger] current user is sampled.')
}
appConfig._isLoggerReady = true
log('[Logger] debug mode: ', debug)
log('[Logger] app info: ', appConfig)
}
_log('[Logger] debug mode: ', debug)
_log('[Logger] app info: ', appConfig)
export function initSentry(options, integrationOptions) {
if (!appConfig._isLoggerReady) {
log('[Logger] [Sentry] failed: Logger is not ready!')
return
}
if (!appConfig._isSampled) {
log('[Logger] [Sentry] failed: current user is not sampled!')
return
}
if (typeof options !== 'object') options = {}
const dsn = options.dsn
if (!dsn) {
log('[Logger] [Sentry] failed: DSN is missing!')
return
}
const defaults = {
debug: appConfig.debug,
release: appConfig.release,
beforeSend: (event) => {
log('[Logger] [Sentry] send: ', event)
return event
},
}
const sentryOptions = {
...defaults,
...options,
}
// fix options
if (!Array.isArray(sentryOptions.integrations)) {
sentryOptions.integrations = []
}
// Vue integration
if (typeof integrationOptions !== 'object') integrationOptions = {}
const vueOptions = integrationOptions.Vue || {}
// Sentry 可以通过以下两种方式找到 Vue
const availableVue = vueOptions.Vue || window.Vue
if (!availableVue) {
log('[Logger] [Sentry] `Vue` not found, Vue integration is **NOT** activated.')
} else {
sentryOptions.integrations.push(new SentryIntegrations.Vue(vueOptions))
log('[Logger] [Sentry] Vue integration is activated.')
}
// dedupe
sentryOptions.integrations.push(new SentryIntegrations.Dedupe())
log('[Logger] [Sentry] options: ', sentryOptions)
Sentry.init(sentryOptions)
// debug
exportGlobal.apply(this)
}
/*
附:Sentry SDK 的初始化参数
https://docs.sentry.io/error-reporting/configuration/?platform=browser
// Common Options
dsn
debug
release
environment
sampleRate
maxBreadcrumbs
attachStacktrace
blacklistUrls
whitelistUrls
// Integration Configuration
integrations
defaultIntegrations
// Hooks
beforeSend
beforeBreadcrumb
*/
/**
* 按比率抽样,返回布尔值(抽中还是没抽中)
* @param {Number} rate 抽样比率
* @return {Boolean}
*/
function sample(rate) {
return Math.random() < rate
}
function log(...args) {
if (appConfig.debug) console.log(...args)
}

@@ -5,3 +5,4 @@ // 捕获并上报 “资源加载失败” 的情况

// 在日志平台未上线时,暂时报到 Sentry
import * as SentryClient from '@sentry/browser'
import { Sentry } from './sentry'
import { log } from './log'

@@ -72,5 +73,17 @@ /**

const resType = getResTypeFromElem(elem)
doReportToSentry(resType, url)
doReportToLoggingPlatform(resType, url)
}
function doReportToSentry(resType, url) {
const msg = `Resource Error: ${resType}: ${url}`
SentryClient.captureMessage(msg, 'warning')
Sentry.captureMessage(msg, 'warning')
}
function doReportToLoggingPlatform(resType, url) {
const name = 'resource-error'
log.event(name, {
type: resType,
url,
})
}

@@ -77,0 +90,0 @@ /**

@@ -1,8 +0,8 @@

import * as SentrySDK from '@sentry/browser'
import { Sentry } from './sentry'
// as a Vue plugin
// export as a Vue plugin
export function install(Vue) {
Vue.prototype.$_Logger = {
Sentry: SentrySDK,
Sentry,
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc