Skip to content

Commit

Permalink
Merge pull request #2046 from botpress/ya-fix-logs
Browse files Browse the repository at this point in the history
fix(logs): fixed botId & missing entries
  • Loading branch information
allardy committed Jul 1, 2019
2 parents 625bc40 + cf0d205 commit cf77920
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 22 deletions.
8 changes: 4 additions & 4 deletions modules/nlu/src/backend/engine.ts
Expand Up @@ -375,7 +375,7 @@ export default class ScopedEngine implements Engine {

const systemEntities = await this.systemEntityExtractor.extract(ds.lowerText, ds.language)

debugEntities(ds.rawText, { systemEntities, patternEntities, listEntities })
debugEntities.forBot(this.botId, ds.rawText, { systemEntities, patternEntities, listEntities })

ds.entities = [...systemEntities, ...patternEntities, ...listEntities]
return ds
Expand Down Expand Up @@ -420,7 +420,7 @@ export default class ScopedEngine implements Engine {
ds.intents = intents
ds.intent = intents[0]

debugIntents(ds.sanitizedText, { intents })
debugIntents.forBot(this.botId, ds.sanitizedText, { intents })

return ds
}
Expand Down Expand Up @@ -455,7 +455,7 @@ export default class ScopedEngine implements Engine {
ds.tokens
)

debugSlots('slots', { rawText: ds.rawText, slots: ds.slots })
debugSlots.forBot(this.botId, 'slots', { rawText: ds.rawText, slots: ds.slots })
return ds
}

Expand All @@ -464,7 +464,7 @@ export default class ScopedEngine implements Engine {
ds.detectedLanguage = lang

if (!lang || lang === 'n/a' || !this.languages.includes(lang)) {
debugLang(`Detected language (${lang}) is not supported, fallback to ${this.defaultLanguage}`)
debugLang.forBot(this.botId, `Detected language (${lang}) is not supported, fallback to ${this.defaultLanguage}`)
lang = this.defaultLanguage
}

Expand Down
5 changes: 4 additions & 1 deletion src/bp/core/routers/admin/bots.ts
Expand Up @@ -139,7 +139,10 @@ export class BotsRouter extends CustomRouter {

return res.sendStatus(200)
} catch (err) {
this.logger.attachError(err).error(`Cannot request bot: ${req.params.botId} for stage change`)
this.logger
.forBot(req.params.botId)
.attachError(err)
.error(`Cannot request bot: ${req.params.botId} for stage change`)
res.status(400)
}
})
Expand Down
1 change: 1 addition & 0 deletions src/bp/core/server.ts
Expand Up @@ -170,6 +170,7 @@ export default class HTTPServer {
this.botsRouter.router.use('/content', this.contentRouter.router)
this.botsRouter.router.use('/converse', this.converseRouter.router)

// tslint:disable-next-line: no-floating-promises
AppLifecycle.waitFor(AppLifecycleEvents.BOTPRESS_READY).then(() => {
this.isBotpressReady = true
})
Expand Down
5 changes: 4 additions & 1 deletion src/bp/core/services/action/action-service.ts
Expand Up @@ -186,7 +186,10 @@ export class ScopedActionService {
const runner = new VmRunner()

const result = await runner.runInVm(vm, code, dirPath).catch(err => {
this.logger.attachError(err).error(`An error occurred while executing the action "${actionName}`)
this.logger
.forBot(this.botId)
.attachError(err)
.error(`An error occurred while executing the action "${actionName}`)
throw new BPError(`An error occurred while executing the action "${actionName}"`, 'BP_451')
})

Expand Down
15 changes: 10 additions & 5 deletions src/bp/core/services/bot-service.ts
Expand Up @@ -245,9 +245,9 @@ export class BotService {
await this.configProvider.mergeBotConfig(botId, newConfigs)
await this.workspaceService.addBotRef(botId, workspaceId)
await this.mountBot(botId)
this.logger.info(`Import of bot ${botId} successful`)
this.logger.forBot(botId).info(`Import of bot ${botId} successful`)
} else {
this.logger.info(`Import of bot ${botId} was denied by hook validation`)
this.logger.forBot(botId).info(`Import of bot ${botId} was denied by hook validation`)
}
} finally {
tmpDir.removeCallback()
Expand Down Expand Up @@ -291,7 +291,9 @@ export class BotService {
throw new Error('New bot id needs to differ from original bot')
}
if (!overwriteDest && (await this.botExists(destBotId))) {
this.logger.warn('Tried to duplicate a bot to existing destination id without allowing to overwrite')
this.logger
.forBot(destBotId)
.warn('Tried to duplicate a bot to existing destination id without allowing to overwrite')
return
}

Expand Down Expand Up @@ -382,7 +384,10 @@ export class BotService {
delete initialBot.pipeline_status.stage_request
return this.configProvider.setBotConfig(initialBot.id, initialBot)
} catch (err) {
this.logger.attachError(err).error(`Error trying to "promote_copy" bot : ${initialBot.id}`)
this.logger
.forBot(newBot.id)
.attachError(err)
.error(`Error trying to "promote_copy" bot : ${initialBot.id}`)
}
}

Expand Down Expand Up @@ -580,7 +585,7 @@ export class BotService {
await this.ghostService.forBot(botId).deleteFolder('/')
await this.ghostService.forBot(botId).importFromDirectory(tmpDir.name)
await this.mountBot(botId)
this.logger.info(`Rollback of bot ${botId} successful`)
this.logger.forBot(botId).info(`Rollback of bot ${botId} successful`)
} finally {
tmpDir.removeCallback()
}
Expand Down
5 changes: 2 additions & 3 deletions src/bp/core/services/dialog/janitor.ts
Expand Up @@ -13,9 +13,8 @@ import { BotService } from '../bot-service'
import { Janitor } from '../janitor'

import { DialogEngine } from './dialog-engine'
import { SessionIdFactory } from './session/id-factory'
import { TimeoutNodeNotFound } from './errors'
import { isObject } from 'util'
import { SessionIdFactory } from './session/id-factory'

const debug = DEBUG('janitor')
const dialogDebug = debug.sub('dialog')
Expand Down Expand Up @@ -110,7 +109,7 @@ export class DialogJanitor extends Janitor {
if (error instanceof TimeoutNodeNotFound) {
dialogDebug.forBot(botId, 'No timeout node found. Clearing context now.')
} else {
this.logger.error(`Could not process the timeout event. ${error.message}`)
this.logger.forBot(botId).error(`Could not process the timeout event. ${error.message}`)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bp/core/services/hook/hook-service.ts
Expand Up @@ -243,12 +243,12 @@ export class HookService {
const botId = _.get(hook.args, 'event.botId')
const vmRunner = new VmRunner()

hook.debug('before execute %o', { path: hookScript.path, botId, args: _.omit(hook.args, ['bp']) })
hook.debug.forBot(botId, 'before execute %o', { path: hookScript.path, botId, args: _.omit(hook.args, ['bp']) })
process.BOTPRESS_EVENTS.emit(hook.folder, hook.args)
await vmRunner.runInVm(vm, hookScript.code, hookScript.path).catch(err => {
this.logScriptError(err, botId, hookScript.path, hook.folder)
})
hook.debug('after execute')
hook.debug.forBot(botId, 'after execute')
}

private logScriptError(err, botId, path, folder) {
Expand Down
4 changes: 2 additions & 2 deletions src/bp/core/services/middleware/event-engine.ts
Expand Up @@ -166,11 +166,11 @@ export class EventEngine {
this.validateEvent(event)

if (event.direction === 'incoming') {
debugIncoming('send', event)
debugIncoming.forBot(event.botId, 'send ', event)
incrementMetric('eventsIn.count')
await this.incomingQueue.enqueue(event, 1, false)
} else {
debugOutgoing('send', event)
debugOutgoing.forBot(event.botId, 'send ', event)
incrementMetric('eventsOut.count')
await this.outgoingQueue.enqueue(event, 1, false)
}
Expand Down
5 changes: 2 additions & 3 deletions src/bp/debug.ts
Expand Up @@ -7,10 +7,9 @@ export const Debug = (mod: string, base = 'bp') => {
available[namespace] = true
const instance = debug(base).extend(mod)
instance.sub = mod => Debug(mod, namespace)
instance.forBot = (botId, message, extra?) => {
instance.forBot = (botId: string, message: string, extra?: any) => {
if (extra) {
const args = typeof extra === 'string' ? { extra, botId } : { ...extra, botId }
return instance(`(${botId}) ${message}`, args)
return instance(`(${botId}) ${message}`, extra, { botId })
} else {
return instance(`(${botId}) ${message}`, { botId })
}
Expand Down
Expand Up @@ -75,9 +75,11 @@
}

.message {
white-space: pre-wrap;
padding-left: 10px;
opacity: 0.8;
color: #888;
word-spacing: 3px;
}

&:hover .message {
Expand Down
Expand Up @@ -145,7 +145,7 @@ class BottomPanel extends React.Component<Props, State> {

handleClearLogs = () => {
this.logs = []
this.forceUpdate()
this.setState({ initialLogs: [] })
}

render() {
Expand Down

0 comments on commit cf77920

Please sign in to comment.