Skip to content

Enhance app insights integration in Boilerplate (#9945)#9950

Merged
msynk merged 1 commit intobitfoundation:developfrom
yasmoradi:9945
Feb 20, 2025
Merged

Enhance app insights integration in Boilerplate (#9945)#9950
msynk merged 1 commit intobitfoundation:developfrom
yasmoradi:9945

Conversation

@yasmoradi
Copy link
Member

@yasmoradi yasmoradi commented Feb 19, 2025

closes #9945

Summary by CodeRabbit

  • New Features

    • Enhanced telemetry support with improved monitoring initialization across multiple platforms.
    • Introduced configuration for a standalone WebAssembly mode to prevent unnecessary script reloads.
    • Added a new telemetry script with error handling for reliable performance and monitoring.
  • Refactor

    • Streamlined the initialization logic for telemetry components, ensuring they are configured and rendered based on the runtime environment.

@yasmoradi yasmoradi requested a review from msynk February 19, 2025 18:49
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

The changes update the initialization of the Application Insights telemetry component across various project files. In code files, a dictionary parameter with IsWasmStandalone set to true is passed during the addition of the component, including a conditional rendering in one case. Additionally, new JavaScript snippets have been added to the HTML files to initialize Application Insights with a placeholder instrumentation key, disabled telemetry, SDK loading configuration, and error handling.

Changes

File(s) Change Summary
src/.../Boilerplate.Client.Maui/MainPage.xaml.cs
src/.../Boilerplate.Client.Web/Program.cs
src/.../Boilerplate.Client.Windows/Program.cs
src/.../Boilerplate.Server.Web/Components/App.razor
Updated the initialization of ApplicationInsightsInit to pass a parameter dictionary with IsWasmStandalone: true. In App.razor, a conditional block checks if renderMode is not null before initializing the component.
src/.../Boilerplate.Client.Maui/wwwroot/index.html
src/.../Boilerplate.Client.Web/wwwroot/index.html
Added a new JavaScript snippet that initializes Application Insights telemetry. The script configures an instrumentation key placeholder, disables telemetry, loads the SDK from a specified URL, and includes error handling.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application Startup
    participant Client as Client Initialization
    participant AI as ApplicationInsightsInit Component
    participant Cond as Conditional Renderer

    App->>Client: Begin startup
    Client->>AI: Add ApplicationInsightsInit with {IsWasmStandalone: true}
    AI-->>Client: Component initialized
    Cond->>AI: If renderMode != null, initialize component with renderMode
Loading
sequenceDiagram
    participant Browser as Browser
    participant HTML as Index.html Script
    participant SDK as Application Insights SDK Server

    Browser->>HTML: Load HTML page
    HTML->>SDK: Request to load telemetry SDK
    SDK-->>HTML: Return SDK (or error if loading fails)
    HTML-->>Browser: Telemetry initialization complete
Loading

Poem

I'm a rabbit with ears so keen,
Hopping through code in fields so green.
New parameters light up the night,
Telemetry scripts take flight.
I nibble on change with delight,
Celebrating updates with a happy bite! 🐰
Hop on, hop on—code's a delight!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Program.cs (1)

38-38: Add clarifying comment for IsWasmStandalone parameter.

While the implementation is correct and consistent with other platforms, consider adding a comment explaining why IsWasmStandalone is set to true, similar to the comment in the Maui implementation.

+            // The App Insights JS SDK is already included in index.html. Use `IsWasmStandalone` to prevent reloading scripts.
             builder.RootComponents.Add(componentType: typeof(BlazorApplicationInsights.ApplicationInsightsInit), selector: "head::after", parameters: ParameterView.FromDictionary(new Dictionary<string, object?> { { nameof(BlazorApplicationInsights.ApplicationInsightsInit.IsWasmStandalone), true } }));
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Windows/Program.cs (1)

101-101: Add clarifying comment for IsWasmStandalone parameter.

While the implementation is correct and consistent with other platforms, consider adding a comment explaining why IsWasmStandalone is set to true, similar to the comments in other implementations.

+        // The App Insights JS SDK is already included in index.html. Use `IsWasmStandalone` to prevent reloading scripts.
         blazorWebView.RootComponents.Add(new RootComponent("head::after", typeof(BlazorApplicationInsights.ApplicationInsightsInit), new Dictionary<string, object?> { { nameof(BlazorApplicationInsights.ApplicationInsightsInit.IsWasmStandalone), true } }));
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/wwwroot/index.html (1)

15-26: Verify the Application Insights initialization snippet configuration.
The inline script block properly initializes the Application Insights telemetry with a placeholder instrumentation key and telemetry disabled (as indicated by the comment). Please confirm that Blazor correctly updates these values at runtime and that the error handling (fallback/retry logic) behaves as intended. As a good-to-have improvement, consider externalizing this inline script to a dedicated JavaScript file if the same snippet is reused across multiple clients to enhance maintainability.

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/index.html (1)

22-33: Confirm consistency and maintainability of the telemetry script block.
The inserted Application Insights snippet mirrors the configuration used in the Maui client—with the instrumentation key preset to a placeholder value and telemetry disabled—ensuring a consistent telemetry initialization across clients. Please verify that when the application starts, these parameters are appropriately updated by Blazor. Also, consider refactoring by externalizing the script if it will be reused elsewhere, which would adhere to DRY principles and ease future maintenance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee08240 and 3f0078c.

📒 Files selected for processing (6)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MainPage.xaml.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/wwwroot/index.html (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Program.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/index.html (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Windows/Program.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Components/App.razor (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (2)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MainPage.xaml.cs (1)

14-15:

Details

❓ Verification inconclusive

LGTM! Well-documented parameter addition.

The comment clearly explains the purpose of setting IsWasmStandalone=true to prevent script reloading, and the implementation is correct.

Verify that the App Insights JS SDK is indeed included in index.html:


🏁 Script executed:

#!/bin/bash
rg -l "cdn\.monitor\.azure\.com.*applicationinsights" wwwroot/index.html

Length of output: 133


LGTM! The parameter addition is well-documented and correctly prevents duplicate script loading.

However, the automated check for the App Insights JS SDK in wwwroot/index.html did not locate the file. Please verify manually (or update the search path) that the SDK is indeed included in the appropriate HTML file—either by locating index.html at its actual repository location or confirming its inclusion through other means.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Components/App.razor (1)

45-52: Excellent optimization of App Insights initialization!

The implementation cleverly optimizes App Insights by:

  1. Starting telemetry ASAP with an initial static render
  2. Properly initializing the service with renderMode when available
  3. Preventing duplicate script loading with IsWasmStandalone

@msynk msynk merged commit ec1806d into bitfoundation:develop Feb 20, 2025
3 checks passed
@yasmoradi yasmoradi deleted the 9945 branch February 20, 2025 06:57
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

Successfully merging this pull request may close these issues.

Boilerplate project template's app insights integration needs improvements

2 participants