Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
frankok opened this issue Jul 31, 2024 · 1 comment

Comments

@frankok
Copy link

frankok commented Jul 31, 2024

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

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <UserSecretsId>*******************************</UserSecretsId>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Storage.Blobs" Version="12.21.1" />
    <PackageReference Include="Azure.Storage.Files.Shares" Version="12.19.1" />
    <PackageReference Include="Azure.Storage.Queues" Version="12.19.1" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.3.1" />
    <PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.4" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
    <PackageReference Include="PnP.Framework" Version="1.16.0" />
    <PackageReference Include="System.Text.Json" Version="8.0.4" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

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

        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
Copy link
Author

frankok commented Sep 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant