pluginsazure-application-insightsmicrosoft-dynamicsdataverse

Dataverse plugin not sending logs to Application Insights


I have a Dataverse Plugin which is registered on a Dynamics 365 environment. I want to send logs from the plugin to Azure Application Insights. I configured the export of data to Application Insights. Dataverse logs do appear in Application Insights but the plugin logs not.

I created a Dynamics Plugin and added ILogger to log information to Application Insights like this:

ILogger logger = (ILogger)serviceProvider.GetService(typeof(ILogger));
logger.LogInformation("Some log information");

and as described in: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/application-insights-ilogger

I also configured the export of dataverse data to application insights based on following instructions: https://learn.microsoft.com/en-us/power-platform/admin/set-up-export-application-insights

Yet, no traces appear in Application Insights (i also check other tables in application insights)

Neither other methods on ILogger write traces to Application Insights.

The method ILogger.IsEnabled(LogLevel) returns False for every LogLevel.


Solution

  • We have solved this problem by updating the "telemetryinstrumentationkey" value on the organization record. This solution was provided to us by Microsoft Support.

    1. First look for the organizationid by running the API query (orgURL)/api/data/v9.2/organizations . The retrieved record has a "telemetryinstrumentationkey". In our case the retrieved value was null.

    2. Open Application Insights to find the instrumentationkey of your instance

    3. Now update the telemetryinstrumentationkey value on your organization record. You can use the web browser's Development Tools console. Within the console, you can use this script to update the Instrumentation Key:

        var queryPath =   (orgURL)/api/data/v9.2/organizations(orgID);
        var param = {};
        param["telemetryinstrumentationkey"] = "<Instrumentation Key GUID from App Insights Instance from step 2>";
      
        var req = new XMLHttpRequest();
        req.open("PATCH", queryPath, true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
      
        req.onreadystatechange = function () {
                 if (this.readyState === 4) {
                     req.onreadystatechange = null;
                     alert(this.status);
                 }
             };
        req.send(JSON.stringify(param));
      
    4. Once this is copied into the console, hit Enter to execute the script, and you should get a (204 – OK) response.

    Surprisingly, when we do another GET of the organisation record (step 1), then the retrieved value for "telemetryinstrumentationkey" remains null. This seems to be normal. Yet, afterwards, traces are appearing in Application Insights as expected.