fix: telemetry
This commit is contained in:
@@ -86,5 +86,5 @@ telemetry:
|
||||
BUGSNAG_ID: 'bb4b324d0675bcbba10025617fd2cec8'
|
||||
BUGSNAG_REMOTE: 'https://notify.bugsnag.com'
|
||||
GA_ID: 'UA-9094100-7'
|
||||
GA_REMOTE: 'https://www.google-analytics.com/collect'
|
||||
GA_REMOTE: 'https://www.google-analytics.com/batch'
|
||||
# ---------------------------------
|
||||
|
@@ -90,9 +90,6 @@ module.exports = {
|
||||
const models = autoload(path.join(WIKI.SERVERPATH, 'models'))
|
||||
|
||||
// Set init tasks
|
||||
|
||||
console.info(migrationSource)
|
||||
|
||||
let initTasks = {
|
||||
// -> Migrate DB Schemas
|
||||
async syncSchemas() {
|
||||
|
@@ -40,6 +40,7 @@ module.exports = {
|
||||
WIKI.logger.info('Starting setup wizard...')
|
||||
require('../setup')()
|
||||
} else {
|
||||
await this.initTelemetry()
|
||||
await require('../master')()
|
||||
this.postBootMaster()
|
||||
}
|
||||
@@ -61,5 +62,20 @@ module.exports = {
|
||||
|
||||
await WIKI.auth.activateStrategies()
|
||||
await WIKI.queue.start()
|
||||
},
|
||||
/**
|
||||
* Init Telemetry
|
||||
*/
|
||||
async initTelemetry() {
|
||||
require('./telemetry').init()
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
WIKI.logger.warn(err)
|
||||
WIKI.telemetry.sendError(err)
|
||||
})
|
||||
process.on('uncaughtException', (err) => {
|
||||
WIKI.logger.warn(err)
|
||||
WIKI.telemetry.sendError(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -35,8 +35,6 @@ module.exports = {
|
||||
* @param {Object} opts Options object
|
||||
*/
|
||||
async upgradeFromMongo (opts) {
|
||||
WIKI.telemetry.sendEvent('setup', 'upgradeFromMongo')
|
||||
|
||||
WIKI.logger.info('Upgrading from MongoDB...')
|
||||
|
||||
let mongo = require('mongodb').MongoClient
|
||||
|
@@ -1,57 +1,89 @@
|
||||
const _ = require('lodash')
|
||||
const axios = require('axios')
|
||||
const bugsnag = require('bugsnag')
|
||||
const path = require('path')
|
||||
const bugsnag = require('@bugsnag/node')
|
||||
const uuid = require('uuid/v4')
|
||||
const qs = require('querystring')
|
||||
const os = require('os')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
cid: '',
|
||||
client: null,
|
||||
enabled: false,
|
||||
init() {
|
||||
this.cid = uuid()
|
||||
bugsnag.register(WIKI.data.telemetry.BUGSNAG_ID, {
|
||||
this.client = bugsnag({
|
||||
apiKey: WIKI.data.telemetry.BUGSNAG_ID,
|
||||
appType: 'server',
|
||||
appVersion: WIKI.version,
|
||||
autoNotify: false,
|
||||
hostname: this.cid,
|
||||
collectUserIp: false,
|
||||
hostname: _.get(WIKI.config, 'telemetry.clientId', uuid()),
|
||||
notifyReleaseStages: ['production'],
|
||||
packageJSON: path.join(WIKI.ROOTPATH, 'package.json'),
|
||||
releaseStage: WIKI.IS_DEBUG ? 'development' : 'production',
|
||||
projectRoot: WIKI.ROOTPATH,
|
||||
useSSL: true
|
||||
})
|
||||
bugsnag.onBeforeNotify((notification, originalError) => {
|
||||
if (!this.enabled) { return false }
|
||||
logger: null,
|
||||
beforeSend: (report) => {
|
||||
if (!WIKI.telemetry.enabled) { return false }
|
||||
}
|
||||
})
|
||||
WIKI.telemetry = this
|
||||
|
||||
if (_.get(WIKI.config, 'logging.telemetry', false) === true) {
|
||||
if (_.get(WIKI.config, 'telemetry.isEnabled', false) === true) {
|
||||
this.enabled = true
|
||||
this.sendOSInfo()
|
||||
}
|
||||
|
||||
return this
|
||||
},
|
||||
sendOSInfo() {
|
||||
this.sendBatchEvents([
|
||||
{
|
||||
eventCategory: 'node-version',
|
||||
eventAction: process.version
|
||||
},
|
||||
{
|
||||
eventCategory: 'os-platform',
|
||||
eventAction: os.platform()
|
||||
},
|
||||
{
|
||||
eventCategory: 'cpu-cores',
|
||||
eventAction: os.cpus().length
|
||||
},
|
||||
{
|
||||
eventCategory: 'db-type',
|
||||
eventAction: WIKI.config.db.type
|
||||
}
|
||||
])
|
||||
},
|
||||
sendError(err) {
|
||||
bugsnag.notify(err, { userId: this.cid })
|
||||
this.client.notify(err)
|
||||
},
|
||||
sendEvent(eventCategory, eventAction, eventLabel) {
|
||||
if (!this.enabled) { return false }
|
||||
this.sendBatchEvents([{
|
||||
eventCategory,
|
||||
eventAction,
|
||||
eventLabel
|
||||
}])
|
||||
},
|
||||
sendBatchEvents(events) {
|
||||
if (!this.enabled || WIKI.IS_DEBUG) { return false }
|
||||
axios({
|
||||
method: 'post',
|
||||
url: WIKI.data.telemetry.GA_REMOTE,
|
||||
headers: {
|
||||
'Content-type': 'application/x-www-form-urlencoded'
|
||||
'Content-type': 'text/plain'
|
||||
},
|
||||
params: {
|
||||
v: 1, // API version
|
||||
tid: WIKI.data.telemetry.GA_ID, // Tracking ID
|
||||
aip: 1, // Anonymize IP
|
||||
ds: 'server', // Data source
|
||||
cid: this.cid, // Client ID
|
||||
t: 'event', // Hit Type
|
||||
ec: eventCategory, // Event Category
|
||||
ea: eventAction, // Event Action
|
||||
el: eventLabel // Event Label
|
||||
}
|
||||
data: events.map(ev => {
|
||||
return qs.stringify({
|
||||
v: 1, // API version
|
||||
tid: WIKI.data.telemetry.GA_ID, // Tracking ID
|
||||
aip: 1, // Anonymize IP
|
||||
ds: 'server', // Data source
|
||||
cid: WIKI.telemetry.cid, // Client ID
|
||||
t: 'event', // Hit Type
|
||||
ec: ev.eventCategory, // Event Category
|
||||
ea: ev.eventAction, // Event Action
|
||||
el: ev.eventLabel // Event Label
|
||||
})
|
||||
}).join('\n')
|
||||
}).then(resp => {
|
||||
if (resp.status !== 200) {
|
||||
WIKI.logger.warn('Unable to send analytics telemetry request.')
|
||||
@@ -59,5 +91,9 @@ module.exports = {
|
||||
}, err => {
|
||||
WIKI.logger.warn('Unable to send analytics telemetry request.')
|
||||
})
|
||||
},
|
||||
generateClientId() {
|
||||
_.set(WIKI.config, 'telemetry.clientId', uuid())
|
||||
return WIKI.config.telemetry.clientId
|
||||
}
|
||||
}
|
||||
|
@@ -24,21 +24,6 @@ WIKI.configSvc.init()
|
||||
|
||||
WIKI.logger = require('./core/logger').init('MASTER')
|
||||
|
||||
// ----------------------------------------
|
||||
// Init Telemetry
|
||||
// ----------------------------------------
|
||||
|
||||
WIKI.telemetry = require('./core/telemetry').init()
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
WIKI.logger.warn(err)
|
||||
WIKI.telemetry.sendError(err)
|
||||
})
|
||||
process.on('uncaughtException', (err) => {
|
||||
WIKI.logger.warn(err)
|
||||
WIKI.telemetry.sendError(err)
|
||||
})
|
||||
|
||||
// ----------------------------------------
|
||||
// Start Kernel
|
||||
// ----------------------------------------
|
||||
|
@@ -71,38 +71,14 @@ module.exports = () => {
|
||||
|
||||
app.get('*', async (req, res) => {
|
||||
let packageObj = await fs.readJson(path.join(WIKI.ROOTPATH, 'package.json'))
|
||||
res.render('setup', {
|
||||
packageObj,
|
||||
telemetryClientID: WIKI.telemetry.cid
|
||||
})
|
||||
res.render('setup', { packageObj })
|
||||
})
|
||||
|
||||
/**
|
||||
* Finalize
|
||||
*/
|
||||
app.post('/finalize', async (req, res) => {
|
||||
WIKI.telemetry.sendEvent('setup', 'finalize')
|
||||
|
||||
try {
|
||||
// Basic checks
|
||||
if (!semver.satisfies(process.version, '>=10.14')) {
|
||||
throw new Error('Node.js 10.14.x or later required!')
|
||||
}
|
||||
|
||||
// Upgrade from WIKI.js 1.x?
|
||||
if (req.body.upgrade) {
|
||||
await WIKI.system.upgradeFromMongo({
|
||||
mongoCnStr: cfgHelper.parseConfigValue(req.body.upgMongo)
|
||||
})
|
||||
}
|
||||
|
||||
// Create directory structure
|
||||
WIKI.logger.info('Creating data directories...')
|
||||
const dataPath = path.join(process.cwd(), 'data')
|
||||
await fs.ensureDir(dataPath)
|
||||
await fs.emptyDir(path.join(dataPath, 'cache'))
|
||||
await fs.ensureDir(path.join(dataPath, 'uploads'))
|
||||
|
||||
// Set config
|
||||
_.set(WIKI.config, 'auth', {
|
||||
audience: 'urn:wiki.js',
|
||||
@@ -149,7 +125,7 @@ module.exports = () => {
|
||||
_.set(WIKI.config, 'sessionSecret', (await crypto.randomBytesAsync(32)).toString('hex'))
|
||||
_.set(WIKI.config, 'telemetry', {
|
||||
isEnabled: req.body.telemetry === true,
|
||||
clientId: WIKI.telemetry.cid
|
||||
clientId: uuid()
|
||||
})
|
||||
_.set(WIKI.config, 'theming', {
|
||||
theme: 'default',
|
||||
@@ -157,6 +133,30 @@ module.exports = () => {
|
||||
})
|
||||
_.set(WIKI.config, 'title', 'Wiki.js')
|
||||
|
||||
// Init Telemetry
|
||||
WIKI.kernel.initTelemetry()
|
||||
WIKI.telemetry.sendEvent('setup', 'install-start')
|
||||
|
||||
// Basic checks
|
||||
if (!semver.satisfies(process.version, '>=10.14')) {
|
||||
throw new Error('Node.js 10.14.x or later required!')
|
||||
}
|
||||
|
||||
// Upgrade from WIKI.js 1.x?
|
||||
if (req.body.upgrade) {
|
||||
WIKI.telemetry.sendEvent('setup', 'install-mongo-upgrade')
|
||||
await WIKI.system.upgradeFromMongo({
|
||||
mongoCnStr: cfgHelper.parseConfigValue(req.body.upgMongo)
|
||||
})
|
||||
}
|
||||
|
||||
// Create directory structure
|
||||
WIKI.logger.info('Creating data directories...')
|
||||
const dataPath = path.join(process.cwd(), 'data')
|
||||
await fs.ensureDir(dataPath)
|
||||
await fs.emptyDir(path.join(dataPath, 'cache'))
|
||||
await fs.ensureDir(path.join(dataPath, 'uploads'))
|
||||
|
||||
// Generate certificates
|
||||
WIKI.logger.info('Generating certificates...')
|
||||
const certs = crypto.generateKeyPairSync('rsa', {
|
||||
@@ -244,6 +244,8 @@ module.exports = () => {
|
||||
await WIKI.models.searchEngines.refreshSearchEnginesFromDisk()
|
||||
await WIKI.models.searchEngines.query().patch({ isEnabled: true }).where('key', 'db')
|
||||
|
||||
WIKI.telemetry.sendEvent('setup', 'install-loadedmodules')
|
||||
|
||||
// Load storage targets
|
||||
await WIKI.models.storage.refreshTargetsFromDisk()
|
||||
|
||||
@@ -305,6 +307,7 @@ module.exports = () => {
|
||||
})
|
||||
|
||||
WIKI.logger.info('Setup is complete!')
|
||||
WIKI.telemetry.sendEvent('setup', 'install-completed')
|
||||
res.json({
|
||||
ok: true,
|
||||
redirectPath: '/',
|
||||
@@ -321,6 +324,7 @@ module.exports = () => {
|
||||
}, 1000)
|
||||
})
|
||||
} catch (err) {
|
||||
WIKI.telemetry.sendError(err)
|
||||
res.json({ ok: false, error: err.message })
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user