Skip to content

Blazor work doesn't seem to take place within an activity #60788

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

Closed
samsp-msft opened this issue Mar 6, 2025 · 3 comments
Closed

Blazor work doesn't seem to take place within an activity #60788

samsp-msft opened this issue Mar 6, 2025 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity

Comments

@samsp-msft
Copy link

While investigating an issue with gen_ai telemetry, I noticed that the work done on a Blazor server doesn't occur within the scope of an Activity, but there is an Activity recorded and emitted by OTel for Blazor requests.

steps to reproduce

  1. Create an Aspire sample application
  • This has OTel configured with the dashboard etc.
  1. Update the counter page code to:
@page "/counter"
@using System.Diagnostics
@rendermode InteractiveServer
@inject ILogger<Counter> logger

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;

        var activity = Activity.Current;
        var ctx = (new HttpContextAccessor()).HttpContext;

        logger.LogInformation("In `IncrementCount`");
    }

}

Adding the ILogger, imports and extra code to IncrementCount()

  1. Set a breakpoint on logger.LogInformation("In IncrementCount"); line, and F5, and click the counter button. The breakpoint will be hit but there will not be an Activity or HttpContext.
  2. Look at the OTel output in the dashboard, there will be a Trace for the call to the Counter Page, and there will be a structured log entry, but they are not associated with each other.
@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Mar 6, 2025
@javiercn
Copy link
Member

javiercn commented Mar 7, 2025

@samsp-msft is this a dupe of #29846 or #53613 we plan to work these out in 10.0, with the Aspire dashboard being our "target"

Is there a reason you are trying to use HttpContextAccessor? It's discouraged in Blazor Server applications (they run inside a websocket, outside of the context of a normal HttpRequest)

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Mar 7, 2025
Copy link
Contributor

Hi @samsp-msft. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity
Projects
None yet
Development

No branches or pull requests

2 participants