Skip to content

Conversation

@ysmoradi
Copy link
Member

@ysmoradi ysmoradi commented Aug 12, 2025

closes #11265

Summary by CodeRabbit

  • New Features

    • Added built-in telemetry: application activity/meter sources and OpenTelemetry wiring.
    • Introduced metrics for image resize duration and ongoing chatbot conversations.
  • Bug Fixes

    • Improved streaming cleanup by completing chat channels after use.
    • Respects per-message cancellation in chatbot actions to prevent unnecessary work.
  • Chores

    • Updated multiple dependencies and tools (Aspire, Microsoft.Extensions.*, Hangfire, MSTest, Microsoft.Identity.Web, WebView2).
    • Updated Aspire Dashboard container image tag.

@ysmoradi ysmoradi requested a review from Copilot August 12, 2025 23:10
@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Centralized package and tool version bumps. Introduces AppActivitySource for OpenTelemetry and registers its meter/source. Adds telemetry metrics: image resize histogram, ongoing conversations UpDownCounter. Improves SignalR chatbot loop with try/finally, cancellation guards, and channel completion. Updates Aspire dashboard image tag.

Changes

Cohort / File(s) Summary
Centralized dependency/tool updates
src/.../Directory.Packages.props, src/.../Server/Boilerplate.Server.AppHost/.config/dotnet-tools.json, src/.../Server/Boilerplate.Server.AppHost/Extensions/IDistributedApplicationBuilderExtensions.cs
Bumps multiple package versions; updates aspire.cli to 9.4.1; changes Aspire Dashboard image tag 9.3→9.4.
OpenTelemetry wiring
src/.../Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs, src/.../Shared/Services/AppActivitySource.cs
Adds AppActivitySource with ActivitySource and Meter; registers meter and tracing source in OpenTelemetry setup.
API metrics (attachments)
src/.../Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs
Adds Stopwatch and records histogram "attachment.upload_resize_duration" with kind label for resized image uploads.
SignalR chatbot telemetry and control
src/.../Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs
Adds UpDownCounter for ongoing conversations with try/finally increment/decrement; adds cancellation checks; completes channel writer at end.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AppHub
  participant AI
  participant Metrics

  Client->>AppHub: Start conversation stream
  AppHub->>Metrics: ongoing_conversations_count +1
  loop Read messages
    AppHub->>AI: Process message (checks cancellation)
    AI-->>AppHub: Response/None
    AppHub-->>Client: Streamed tokens
  end
  AppHub->>Client: Complete stream
  AppHub->>AppHub: channel.Writer.Complete()
  AppHub->>Metrics: ongoing_conversations_count -1
Loading
sequenceDiagram
  participant Client
  participant API
  participant Storage
  participant Metrics

  Client->>API: UploadAttachment(file)
  alt NeedsResize
    API->>API: Stopwatch start
    API->>Storage: Write resized image
    API->>Metrics: Record histogram attachment.upload_resize_duration(ms, kind)
  else No resize
    API->>Storage: Write original
  end
  API-->>Client: 200 OK
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Add required OpenTelemetry usages (#11265)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Add channel.Writer.Complete() to finalize stream (src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs) Stream completion is a control-flow change not directly tied to adding OpenTelemetry usages.
Add cancellation guards in AI function hooks (src/.../Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs) Cancellation handling improvements are unrelated to the OpenTelemetry requirement.

Poem

A rabbit taps its tiny keys—tik tik—
New meters hum, traces flicker quick.
A stopwatch blinks for pics we shrink,
The chat winds down with a tidy clink.
Carrots raised to dashboards new—
Hop, hop! Our telemetry grew.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds required OpenTelemetry usage to the bit Boilerplate template by creating a centralized activity source and enhancing telemetry instrumentation across the application.

  • Creates a new AppActivitySource class to provide centralized ActivitySource and Meter instances
  • Integrates custom metrics and tracing into OpenTelemetry configuration
  • Adds telemetry tracking for chatbot conversations and image resize operations

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Shared/Services/AppActivitySource.cs New centralized class providing ActivitySource and Meter instances for OpenTelemetry
src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs Registers custom meter and activity source with OpenTelemetry configuration
src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs Adds conversation count tracking and proper channel cleanup
src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs Adds histogram metric for image resize duration tracking
src/Server/Boilerplate.Server.AppHost/Extensions/IDistributedApplicationBuilderExtensions.cs Updates Aspire dashboard version from 9.3 to 9.4
src/Server/Boilerplate.Server.AppHost/.config/dotnet-tools.json Updates Aspire CLI version from 9.4.0 to 9.4.1
src/Directory.Packages.props Updates multiple package versions including Aspire, Hangfire, and other dependencies

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: 6

🔭 Outside diff range comments (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs (1)

188-200: Resolve potential missing namespace for Stopwatch and enrich metric with unit/description.

If there’s no global using for System.Diagnostics, this won’t compile. Also, add unit/description to the histogram for better OTel semantic clarity.

Apply this diff:

-                Stopwatch stopwatch = Stopwatch.StartNew();
+                var stopwatch = System.Diagnostics.Stopwatch.StartNew();
@@
-                AppActivitySource.CurrentMeter.CreateHistogram<double>("attachment.upload_resize_duration")
-                    .Record(stopwatch.Elapsed.TotalMilliseconds, new KeyValuePair<string, object?>("kind", kind.ToString()));
+                AppActivitySource.CurrentMeter.CreateHistogram<double>(
+                        "attachment.upload_resize_duration",
+                        unit: "ms",
+                        description: "Elapsed time to resize and persist an uploaded image")
+                    .Record(
+                        stopwatch.Elapsed.TotalMilliseconds,
+                        new KeyValuePair<string, object?>("attachment.kind", kind.ToString()));

Optional follow-up: pre-create and reuse the histogram via AppActivitySource (see my comment in AppActivitySource.cs).

🧹 Nitpick comments (3)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs (1)

188-200: Consider adding a span around the resize/write step for trace correlation.

A short Activity span helps correlate the metric with request traces and enriches diagnostics for slow uploads.

Example (outside this hunk):

using var activity = AppActivitySource.CurrentActivity.StartActivity("attachment.resize_and_write");
activity?.SetTag("attachment.kind", kind.ToString());
// do the work...
activity?.SetTag("elapsed.ms", stopwatch.Elapsed.TotalMilliseconds);
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs (2)

89-91: Good addition: early cancellation guard in tool function

Early return avoids unnecessary work and scope creation when the message is canceled.

Given this function handles PII (email address, conversation history), consider masking or redacting before logging to mitigate PII leakage risks.


174-177: Redundant cancellation passing in ReadAllAsync enumeration

You pass the cancellationToken to both ReadAllAsync(cancellationToken) and WithCancellation(cancellationToken). One is sufficient. Prefer relying on ReadAllAsync’s token.

Apply:

-            await foreach (var str in channel.Reader.ReadAllAsync(cancellationToken).WithCancellation(cancellationToken))
+            await foreach (var str in channel.Reader.ReadAllAsync(cancellationToken))
             {
                 yield return str;
             }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 89ceab9 and cf6c82e.

📒 Files selected for processing (7)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Packages.props (5 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs (2 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs (3 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.AppHost/.config/dotnet-tools.json (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.AppHost/Extensions/IDistributedApplicationBuilderExtensions.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs (2 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/AppActivitySource.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/AppActivitySource.cs (1)
  • AppActivitySource (8-13)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/AppActivitySource.cs (1)
  • AppActivitySource (8-13)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs (2)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/DiagnosticLog/DiagnosticLoggerProvider.cs (1)
  • ILogger (14-20)
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Services/AppActivitySource.cs (1)
  • AppActivitySource (8-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build and test
🔇 Additional comments (5)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.AppHost/Extensions/IDistributedApplicationBuilderExtensions.cs (1)

17-19: Confirm image tag strategy for Aspire Dashboard

According to Microsoft’s container tagging guidance, using the minor tag (9.4) will automatically float to the latest patch release in the 9.4 line. As of now, the latest published patch is 9.4.0, and 9.4.1 is pending release:

  • If you intend to always pick up the newest 9.4.x dashboard image, leave the tag as 9.4.
  • If you require a truly immutable reference, pin to the explicit patch (e.g., mcr.microsoft.com/dotnet/aspire-dashboard:9.4.0 today, or switch to 9.4.1 once it’s available).

No code changes are needed here unless you specifically want to fix to a patch version.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.AppHost/.config/dotnet-tools.json (1)

5-7: LGTM: aspire.cli bump aligns with package updates.

The tool version 9.4.1 is consistent with the central package updates and should keep the CLI in sync.

src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Packages.props (1)

49-55: Version bumps look coherent across Aspire, AI, MSTest, and WebView2.

The updates are consistent and align with the rest of the PR changes (Aspire 9.4.1, AI 9.8.0, MSTest 3.10.2, WebView2 1.0.3405.78). No API surface changes visible here to flag.

Also applies to: 56-57, 63-63, 76-76, 106-106, 30-30, 125-126

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs (1)

132-151: AddSource registrations are intentional and non-redundant
Both calls register different ActivitySource names:

  • builder.Environment.ApplicationName (your ASP .NET Core app’s entry assembly name)
  • AppActivitySource.CurrentActivity.Name (“Boilerplate”)

Since they target separate ActivitySource instances, both registrations are required.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs (1)

170-181: LGTM: try/finally with UpDownCounter maintains accurate gauge for active conversations

Increment on entry and decrement on exit ensures correctness across normal completion and cancellations.

@ysmoradi ysmoradi merged commit 0215ec5 into bitfoundation:develop Aug 13, 2025
6 checks passed
@ysmoradi ysmoradi deleted the 11265 branch August 13, 2025 13:42
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.

bit Boilerplate misses required open telemetry usages

1 participant