Installation
npm install --save botbuilder-calling-logging
Peer dependencies
npm install --save documentdb azure-storage botbuilder-calling
Usage
TypeScript
import { BotCallLogger } from 'botbuilder-calling-logging';
import { BlobService } from 'azure-storage';
import { DocumentClient } from 'documentdb';
import { UniversalBot } from 'botbuilder-calling';
const callbot = new UniversalBot();
const logger = new BotCallLogger(new DocumentClient(), {
documents: {
databaseName: 'logs1',
collectionName: 'bot1',
},
blobs: {
blobService: new BlobService(),
options: { containerName: 'botcalls', }
},
});
logger.events.on('error', console.error);
callbot.use(logger);
Error handling
Any errors encountered by the DocumentClient
or BlobService
are not returned through the bot middleware service. In order to capture these errors, listen to the logger's error
event.
logger.events.on('error', console.error);
Advanced
DocumentDB Partitioning
For large-scale DocumentDB collections (RU > 10K), the recommended partitionKey is /address/conversation/id
Log format
Logs are stored in DocumentDB as JSON documents. Any binary attachments (images, speech) are stored as attachments in DocumentDb, as well as on Azure Blob Storage, if it is configured.
Extending the data store
To persist logs or blobs in arbitrary stores, implement your own DocumentWriter
and BlobWriter
classes (see the botbuilder-logging
package). Then write your own bot middleware that calls BotLogWriter.enqueue
. See class BotCallLogger
for sample implementation.