pnp / pnpframework

PnP Framework is a .NET library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions
https://pnp.github.io/pnpframework/
MIT License
211 stars 144 forks source link

Web.ApplyProvisioningTemplate stops logging to App Insights if template includes ClientSidePages #1046

Open frankok opened 3 months ago

frankok commented 3 months ago

Not sure if this is the right place for this post, since it includes so many different components. But here goes...

I have an Azure Function written in C# and developed in Visual Studio 2022. It runs on .NET 8.0 In-Process, and I'm using PnP.Framework 1.16.0.

Here's the rest of the project details, if needed:

Visual Studio Project Details

```html net8.0 v4 ******************************* PreserveNewest PreserveNewest Never ```

The function is supposed to apply a PnP Provisioning template to a SharePoint Online site. Here's the method that applies the template:

ApplyPnPTemplate C# Method

```c# public static async Task ApplyPnPTemplate(AuthenticationManager authManager, string siteUrl, ProvisioningTemplate pnpTemplate, bool? clearNavigation, ILogger log = null) { string logPrefix = "ApplyPnPTemplate | "; if (pnpTemplate == null) throw new Exception("PnP Template is null/undefined"); using (var ctx = await authManager.GetContextAsync(siteUrl)) { // Added for testing if this could have something to do with the problem ctx.RequestTimeout = Timeout.Infinite; ProvisioningTemplateApplyingInformation ptai = new ProvisioningTemplateApplyingInformation(); if (log != null) { try { ptai.ProgressDelegate = delegate (String message, Int32 progress, Int32 total) { log?.LogInformation(logPrefix + string.Format("{0:00}/{1:00} - {2}", progress, total, message)); }; ptai.MessagesDelegate = (message, messageType) => { log?.LogInformation(logPrefix + message); }; ptai.SiteProvisionedDelegate = (title, siteUrl) => { log?.LogInformation(logPrefix + $"Site Provisioned: {title} ({siteUrl})"); }; } catch (Exception err) { log?.LogError(logPrefix + err.Message); throw; } } if (clearNavigation.HasValue) { try { log?.LogInformation($"{logPrefix}Clearing navigation..."); ptai.ClearNavigation = clearNavigation.Value; } catch (Exception err) { log?.LogError(logPrefix + err.Message); } } try { ctx.Web.ApplyProvisioningTemplate(pnpTemplate, ptai); } catch (Exception err) { log?.LogError(logPrefix + err.Message); throw; } } } ```

I deploy the function to an Azure Function, which has Application Insights enabled.

If I run with a provisioning template without any ClientSidePages defined, the logging works just fine. The Invocation appears under the function log as expected:

image

The provisioning schema used during testing is attached in this XML file: PP365-Minimumtest.zip

Please see the attachments LogStreamWithNoClientSidePages.txt and ApplicationInsightsWithNoClientSidePages.csv for example results: LogStreamWithNoClientSidePages.txt ApplicationInsightsWithNoClientSidePages.csv

However, if I include ClientSidePages (even just one with the minimum required settings), the logging to Application Insights stops completely. Subsequent calls to the function (or any other functions I have in the same app) won't log to Application Insights at all! I actually have to restart the Function App to make it start logging to Application Insights again.

Please see the attachments LogStreamWithClientSidePages.txt and ApplicationInsightsWithClientSidePages.csv for example results: ApplicationInsightsWithClientSidePages.csv LogStreamWithClientSidePages.txt

Funny thing is: If I run the function locally (debugging from VS), everything works fine. In both cases, I can see that the logging to the Application Insights is completed.

I guess somewhere, maybe in the Azure Function, there is an incompatibility issue. But I cannot find it. Here are some of the details from the Azure Function:

image

It's important to mention that the function itself works as expected, and it finishes the run as expected in all cases (as the Log Streams shows). It's only in the Application Insights it fails to complete the logging, and hence mark the run as completed and therefore it won't appear in the Invocation list for the Function App.

I have used many hours trying to figure out why this is failing. Actually, this function is just a small part of a much larger provisioning function we have created. This needs to be upgraded from v2 (for supportability), and then this issue came up.

I hope someone could take some time and look through this, and maybe help me figure out this issue. Any feedback or comments are appreciated!

Kind regards,

Frank

frankok commented 2 months ago

Hi, Anyone on the team care to comment on this? Thanks :)