Skip to content

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

Closed
@samsp-msft

Description

@samsp-msft

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Status: No Recent Activityarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions