Tim
Tim

Reputation: 11

Can't Seem to See Custom Telemetry in App Insights

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

Answers (1)

Matt Stannett
Matt Stannett

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:

  1. Get the latest version of the Bot Framework Emulator.
  2. Update your TelemetryMiddleware class to have a the following field private IBotTelemetryClient _telemetryClient;
  3. Update your TelemetryMiddleware constructor to assign the value from the telemetryClient parameter to your new _telemetryClient field.
  4. Update the call inside OnReceiveActivityAsync to use the new _telemetryClient field instead of the TelemetryClient class (you are calling TrackEvent statically currently which isn't what you want.
  5. Run your bot locally using the Bot Framework Emulator.
  6. Add a breakpoint on the line where you call TrackEvent
  7. Create the scenario which should trigger OnReceiveActivityAsync (send a message to the bot).
  8. Use F10 to step over the TrackEvent line and ensure that it is called successfully.
  9. At this stage I would also inspect your variables to ensure they have the values that you expect.
  10. Wait for the event to flow through to App Insights (might take up to 5 minutes).
  11. If this still does not work I would create a new Application Insights API key and updating the following places with the new value:
    • For local testing:
    • Your appsettings.json file so that you can test locally.
    • For production:
    • The Application Insights Instrumentation key under the Settings tab of your Web App Bot in Azure.
    • Also check that the value for 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.
  12. Follow the steps above to test locally using the emulator.
  13. Once the logs are flowing through locally use the Test in Web Chat functionality to ensure that it is working in production.

Upvotes: 2

Related Questions