Reputation: 11
I tried adding custom telemetry per the docs (https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-telemetry?view=azure-bot-service-4.0).
I am missing something because I cannot find my custom event in the App Insights logs.
I tried interacting with the bot and searching the App Insights logs for "VeryImportantProperty" and "VeryImportantValue"
I wrote this class:
public class TelemetryMiddleware : TelemetryLoggerMiddleware
{
public TelemetryMiddleware(IBotTelemetryClient telemetryClient, bool logPersonalInformation)
: base(telemetryClient, logPersonalInformation)
{
}
protected override async Task OnReceiveActivityAsync(Activity activity, CancellationToken cancellation)
{
Dictionary<string, string> propertyItems = new Dictionary<string, string>
{
{"VeryImportantProperty", "VeryImportantValue" }
};
var properties = await FillReceiveEventPropertiesAsync(activity, propertyItems);
TelemetryClient.TrackEvent(TelemetryLoggerConstants.BotMsgReceiveEvent, properties);
}
}
I added it in startup.cs as a service available for injection:
services.AddSingleton<IMiddleware, TelemetryMiddleware>();
I also added all the other items named in the article required as injectable services.
I deployed the bot and interacted with it, but I cannot find my VeryImportantValue or property even after a full search of my App Insights logs.
I’m sure I am missing something, but from the docs, I cannot determine what it is.
Any ideas or pointers in the right direction?
Upvotes: 1
Views: 970
Reputation: 2728
You should be able to see these events by going to Azure Portal > All Resources > Application Insights Resource > Overview page > Logs (Analytics)
which is along the top, above the details for the Application Insights resource.
Then if you enter the following for your query:
customEvents
| where name == "BotMessageReceived"
and click run (you may have to select the query text you entered before clicking run.
Your VeryImportantProperty
data should show under the customDimensions
column.
The getting started information is available here.
Edit
If you still cannot see the log entries then you will need to debug where the issue is. The steps I would recommend are:
TelemetryMiddleware
class to have a the following field private IBotTelemetryClient _telemetryClient;
TelemetryMiddleware
constructor to assign the value from the telemetryClient
parameter to your new _telemetryClient
field.OnReceiveActivityAsync
to use the new _telemetryClient
field instead of the TelemetryClient
class (you are calling TrackEvent
statically currently which isn't what you want.TrackEvent
OnReceiveActivityAsync
(send a message to the bot).F10
to step over the TrackEvent
line and ensure that it is called successfully.Application Insights Instrumentation key
under the Settings
tab of your Web App Bot in Azure.Application Insights Application Id
under the Settings
tab of your Web App Bot in Azure matches the Application Id
value under the API Access
tab of your Application Insights resource.Upvotes: 2