Monitoring, Logging, and Telemetry|Mastering Microsoft Teams Bots 5.3
5.3 Monitoring, Logging, and Telemetry
Launching a bot is exciting. But keeping it running smoothly — that’s where the real work begins.
Just like any application in production, your Microsoft Teams bot needs logging, monitoring, and visibility. Because when something goes wrong (and it will), you need answers fast: Did the message fail to send? Was there an error in the backend? Did authentication break? Did the user get the card?
This section walks you through how to observe your bot in the real world using tools like logs, telemetry, and Azure Application Insights.
5.3.1 Why Monitoring Matters
- 🧠 Understand how users interact with your bot
- 🔍 Diagnose unexpected behavior or crashes
- 📊 Track performance metrics and trends
- 📣 Get alerted to problems before users report them
Monitoring isn’t an afterthought — it’s your bot’s lifeline.
5.3.2 Logging 101
At a minimum, your bot should log:
- Incoming messages (text, user ID, timestamp)
- Key events (e.g., dialog started, card sent)
- Warnings (invalid input, API timeouts)
- Errors (exceptions, failed external calls)
In Node.js:
console.log("User message:", context.activity.text);
console.error("Failed to send card:", error);
In .NET:
_logger.LogInformation("Received message: {Text}", turnContext.Activity.Text);
_logger.LogError(ex, "Error while handling activity.");
5.3.3 Using Azure Application Insights
For full telemetry, Microsoft recommends Application Insights — a service that tracks logs, requests, failures, performance metrics, and usage patterns.
Steps to enable it:
- Create an Application Insights resource in Azure
- Add the Instrumentation Key or Connection String to your app settings
- Configure your SDK (Bot Framework SDK supports this out of the box)
Node.js example:
const appInsights = require("applicationinsights");
appInsights.setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY).start();
const client = appInsights.defaultClient;
client.trackEvent({ name: "UserMessage", properties: { text: messageText } });
.NET example:
services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]);
5.3.4 What to Track
Track both technical and user-oriented events:
- Events: Message received, dialog started, card clicked
- Exceptions: API failures, timeouts, unhandled errors
- Performance: Response time, latency, message throughput
- Custom Metrics: Tasks created, reminders sent, users onboarded
5.3.5 Setting Up Alerts
Azure Monitor can send alerts based on conditions in App Insights:
- 500+ errors in the last hour? Trigger an alert.
- Bot response time exceeds 5 seconds? Send an email.
This helps you catch issues early, often before the end user notices.
5.3.6 Debugging in Production
If something goes wrong, App Insights lets you:
- Replay user sessions (via logs and traces)
- Search by user ID, message text, or time range
- Correlate logs across requests and services
This is especially useful for intermittent bugs or unexpected behaviors.
5.3.7 Summary
Your bot doesn’t just need a voice — it needs ears. Logging and monitoring let you listen to what’s happening behind the scenes. And when your bot is in production, that listening turns into insight, and that insight turns into confidence.
In the next part, we’ll explore real-world use cases — practical bots that solve problems for IT teams, project managers, and customer support agents.
Shohei Shimoda
I organized and output what I have learned and know here.タグ
検索ログ
Development & Technical Consulting
Working on a new product or exploring a technical idea? We help teams with system design, architecture reviews, requirements definition, proof-of-concept development, and full implementation. Whether you need a quick technical assessment or end-to-end support, feel free to reach out.
Contact Us