Logging and Monitoring¶
This step covers how to monitor your Azure Communication Services (ACS) resource and configure SDK logging in JavaScript.
1. SDK Logging Configuration (Node.js)¶
The ACS JavaScript SDK uses the @azure/logger package. You can configure it to output logs to the console.
const { setLogLevel } = require("@azure/logger");
// Set the log level
setLogLevel("info");
// Use ACS client as usual
const { CommunicationIdentityClient } = require("@azure/communication-identity");
// ...
2. Browser SDK Logging¶
In the browser, you can capture logs from the Calling and Chat SDKs.
import { setLogLevel } from "@azure/logger";
// Capture logs in the browser console
setLogLevel("verbose");
// You can also redirect logs to a custom function
setLogLevel("info", (message) => {
console.log(`[ACS Log]: ${message}`);
});
3. Azure Monitor Integration¶
ACS is integrated with Azure Monitor. You can view metrics and logs in the Azure Portal.
- Navigate to your ACS resource.
- Under Monitoring, select Metrics.
- Choose a metric, such as SMS Sent or Email Sent.
- You can also create Alerts based on these metrics.
4. Application Insights Setup (Node.js)¶
To get deeper insights into your Node.js application's performance and dependencies, integrate with Azure Application Insights.
const appInsights = require("applicationinsights");
appInsights.setup("<your-instrumentation-key>").start();
const client = appInsights.defaultClient;
client.trackTrace({ message: "Monitoring ACS operation performance." });
5. Diagnostic Settings¶
To store logs for long-term analysis, configure diagnostic settings.
- Navigate to your ACS resource.
- Under Monitoring, select Diagnostic settings.
- Click Add diagnostic setting.
- Select the logs you want to collect (e.g., SMS Operational Logs, Email Operational Logs).
- Choose a destination, such as a Log Analytics workspace.
6. KQL Queries for Monitoring¶
Once your logs are in a Log Analytics workspace, you can query them using Kusto Query Language (KQL).
SMS Sent Summary¶
ACSSmsOperational
| where OperationName == "SmsSend"
| summarize Count=count() by ResultType, ResultSignature, bin(TimeGenerated, 1h)
| render timechart
Email Delivery Success Rate¶
ACSEmailOperational
| where OperationName == "EmailSend"
| summarize SuccessCount=countif(ResultType == "Succeeded"), TotalCount=count()
| extend SuccessRate = (SuccessCount * 100.0) / TotalCount