
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
botbuilder-logging
Advanced tools
Logging middleware for botbuilder. Uses DocumentDb and Azure Blob to persist bot events.
This package is compatible with Bot Framework SDK version
3.x
. If you are using Bot Framework4.x
please switch to botbuilder-logging@preview.
npm install botbuilder-logging
npm install documentdb azure-storage botbuilder
azure-storage
is used to store binary data, which is typically only used in IVR bots. If you are not using an IVR bot, you can safely omit this peer dependency.
Attach a BotLogger
middleware instance to your UniversalBot
to automatically persist all bot Activity objects.
const { ChatConnector, UniversalBot } = require('botbuilder');
const { BotLogger, writeLog } = require('botbuilder-logging');
const { DocumentClient } = require('documentdb');
// your documentdb instance
const documentdb = new DocumentClient(process.env.DDB_URI, {
masterKey: process.env.DDB_KEY
});
// your chat connector
const connector = new ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
// your bot
const bot = new UniversalBot(connector, (session) => {
session.send(`You said: ${session.message.text}`);
});
// attach logging middleware
bot.use(new BotLogger(documentdb, {
documents: {
databaseName: 'bot',
collectionName: 'logs',
},
}));
Log messages are pushed into a queue to avoid blocking the request, so errors are not available from the calling code.
Instead, attach an error event handler at the time the BotLogger
is created
botLogger.events.on('error', (err) => console.error(err));
Use the writeLog
function to persist arbitrary payloads from within your bot logic.
const { BotLogger, writeLog } = require('botbuilder-logging');
bot.dialog('greetings', [
(session) => {
builder.Prompts.text(session, 'Hi! What is your name?');
},
(session, results) => {
writeLog(session, 'info', results); // log the response
session.endDialog(`Hello ${results.response}!`);
},
]);
IVR bots can be configured to collect raw audio streams, which can be stored by this logger. To enable blob storage, pass an azure-storage
instance in the BotLogger constructor:
const { BlobService } = require('azure-storage');
const blobService = new BlobService(process.env.BLOB_ACCOUNT, process.env.BLOB_KEY);
// attach logging middleware with blob instance
bot.use(new BotLogger(documentdb, {
documents: {
databaseName: 'bot',
collectionName: 'logs',
},
blobs: {
blobService,
options: { container: 'botblobs' }
}
}));
Any available audio data will automatically be stored in the configured blob container using a value of { $blob: 'URI' }
where URI points to your blob storage account and includes a Shared Access Signature (SAS).
The full definition of the BotLogger
options is:
interface BotLoggerOptions {
/** Document Db options */
documents: {
/** DocumentDb database name (created if it does not exist) */
databaseName: string;
/** DocumentDb collection name (created if it does not exist) */
collectionName: string;
/** Default configuration for created collections */
defaults?: {
/** Collection throughput for created collections */
collectionThroughput?: number;
/** Default time-to-live for created collections */
ttl?: number;
/** Partition key to use, if the collection is partitioned */
partitionKey?: string;
};
};
/** Azure Storage configuration */
blobs: {
/** Azure BlobService instance that will write media attachments */
blobService: BlobService;
/** Azure Storage options */
options: {
/** Blob container where media attachments will be stored */
containerName: string;
/** Use this shared access policy when linking log events to media blobs (default: read-only, expires in year 2099) */
sasPolicy?: SharedAccessPolicy;
},
},
/** Number of simultaneous writes before queueing (default: 1) */
concurrency?: number;
/** Any properties that should NOT be visible in logs (e.g. "state.user.private.password"). For supported syntax, see `lodash.get` module. */
maskedProperties?: string[];
}
All of the available properties on each incoming and outbound Activity are automatically stored by the middleware.
The TypeScript interface for stored log entries is defined as
interface LogEntry {
date: Date;
conversation: Partial<IAddress>;
type: string;
data: any;
}
The serializer has special handling for certain JavaScript types found in the data
property:
function
is stored as { $function: null }
Error
object is stored as { $error: { name: err.name, message: err.message, stack: err.stack } }
Buffer
object is stored as { $blob: 'URI' }
, where URI is a string that points to a stored blobDate
object is stored as its .toISOString()
value{ $object: null }
Nested objects are stored recursively using
Object.keys
To persist logs in other stores, extend the BaseBotLogger
class, providing your own DocumentWriter
and BlobWriter
implementations.
FAQs
Logging middleware for botbuilder. Uses DocumentDb and Azure Blob to persist bot events.
The npm package botbuilder-logging receives a total of 2 weekly downloads. As such, botbuilder-logging popularity was classified as not popular.
We found that botbuilder-logging demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.