OpenTelemetry & Blazor Hybrid: Spans/Activities are not logging to Console/File

I have a Blazor Hybrid application, where I’m attempting to use OpenTelemetry + NLog to log client information to a file on disk. I’m trying to get the ActivitySource entries to log to my log file, and console, so I can see the timespan and other information. I need some help getting everything configured correctly (and reducing the what information is being logged… (see info below).

Below is my setup:

Basic Info

Using .NET8, with a Blazor Hybrid project. There is no appsettings.json entries for open telemetry. NLog logging to the file is working as desired. OT is logging to the console… but it’s not useful information to me (currently) and the app is very slow when enabled:

LogRecord.Timestamp:               2024-05-13T14:21:06.2594275Z
LogRecord.CategoryName:            Microsoft.AspNetCore.Components.RenderTree.Renderer
LogRecord.Severity:                Debug
LogRecord.SeverityText:            Debug
LogRecord.Body:                    Rendering component {ComponentId} of type {ComponentType}
LogRecord.Attributes (Key:Value):
    ComponentId: 82
    ComponentType: MudBlazor.MudOverlay
    OriginalFormat (a.k.a Body): Rendering component {ComponentId} of type {ComponentType}
LogRecord.EventId:                 3
LogRecord.EventName:               RenderingComponent

Resource associated with LogRecord:
service.name: <APP NAME>
service.instance.id: 32a40416-826e-444a-a138-485d89f3ed32
telemetry.sdk.name: opentelemetry
telemetry.sdk.language: dotnet
telemetry.sdk.version: 1.8.1

LogRecord.Timestamp:               2024-05-13T14:21:06.2778115Z
LogRecord.CategoryName:            Microsoft.AspNetCore.Components.RenderTree.Renderer
LogRecord.Severity:                Debug
LogRecord.SeverityText:            Debug
LogRecord.Body:                    Rendering component {ComponentId} of type {ComponentType}
LogRecord.Attributes (Key:Value):
    ComponentId: 83
    ComponentType: MudBlazor.MudElement
    OriginalFormat (a.k.a Body): Rendering component {ComponentId} of type {ComponentType}
LogRecord.EventId:                 3
LogRecord.EventName:               RenderingComponent

The ActivitySource is being created in a helper class that also implements IDisposable and is doing all the necessary disposal, etc. If the class is needed, I will edit to show, but the activity is created like so:

        public Telemetry([CallerMemberName] string methodName = "")
        {
            _MethodName = methodName;
            _Activity = TelemetryConstants.ActivitySource.StartActivity(_MethodName);
            AddTag("operation.datetimeoffset.utcnow.begin", DateTimeOffset.UtcNow.ToString(_DateFormat));
        }

MauiProgram.cs

var builder = MauiApp.CreateBuilder();

...

builder.Services.AddOpenTelemetry()
    .ConfigureResource(resource => 
        resource.AddService(serviceName: TelemetryConstants.ServiceName, serviceVersion: TelemetryConstants.ServiceVersion)
    )
    .WithTracing(tracing =>
    {
        tracing
            .AddSource(TelemetryConstants.ServiceName)
            .AddConsoleExporter(options =>
            {
                options.Targets = OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Debug;
            });
    })
    .WithMetrics(builder =>
    {
        builder.AddConsoleExporter(options =>
        {
            options.Targets = OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Debug;
        });
    })
    ;

builder.Logging.ClearProviders();
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddNLog();

builder.Logging.AddOpenTelemetry(options =>
{
    options
        .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(TelemetryConstants.ServiceName))
        .AddConsoleExporter(options =>
        {
            options.Targets = OpenTelemetry.Exporter.ConsoleExporterOutputTargets.Debug;
        });
});

CSProj Package References

    <ItemGroup>
        <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.21" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
        <PackageReference Include="MudBlazor" Version="6.19.1" />
        <PackageReference Include="NLog" Version="5.3.2" />
        <PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />
        <PackageReference Include="NLog.Targets.MauiLog" Version="8.0.0" />
        <PackageReference Include="OpenTelemetry" Version="1.8.1" />
        <PackageReference Include="OpenTelemetry.Api" Version="1.8.1" />
        <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.8.1" />
        <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
    </ItemGroup>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật