net core, open telemetry, serilog and application insights

Matthew Newboult 0 Reputation points
2024-03-13T11:54:20.1366667+00:00

I'm using .net core (8) and have Serilog enabled and am using Open Telemetry to push traces to Azure App Insights. I'm using the correct format in Serilog:

Log.Information("test {@msg}", msg);

All is working but the 'Custom Dimensions' only show the message type and I don't see the structured log. I can serialize the model but that defeats the point of having structured logging in the first place. I've tried all sorts but nothing seems to change this. Here's how I've wired up Open Telemetry and Serilog.

services.AddOpenTelemetry()
            .ConfigureResource(builder => ConfigureResource(
                builder, 
                cfg.GetSection("Application:Name").Value ?? "", 
                cfg.GetSection("Application:Version").Value ?? ""))
            .WithTracing(x => x
                .AddSource(DiagnosticHeaders.DefaultListenerName)
                .AddAzureMonitorTraceExporter(o =>
                {
                    o.ConnectionString = cfg.GetSection("AzureServiceBus:ApplicationInsightsConnectionString").Value;
                }))
            .WithMetrics(x => x.AddMeter(InstrumentationOptions.MeterName)
                .AddAzureMonitorMetricExporter(o =>
                {
                    o.ConnectionString = cfg.GetSection("AzureServiceBus:ApplicationInsightsConnectionString").Value;
                }))
            .UseAzureMonitor();
Log.Logger = new LoggerConfiguration()
                    .MinimumLevel.Information()
                    .WriteTo.Console()
                    .Enrich.WithProperty("ApplicationName", cfg["Application:Name"])
                    .WriteTo.ApplicationInsights(
                        cfg["AzureServiceBus:ApplicationInsightsConnectionString"],
                        new TraceTelemetryConverter())
                    .CreateLogger();
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,522 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,431 Reputation points
    2024-03-15T11:45:34.25+00:00

    This is a duplicate of https://stackoverflow.com/questions/78153592/serilog-open-telemetry-and-azure-app-insights and Matthew Newboult has self-resolved the issue. Thanks for sharing your resolution Matthew Newboult. Sharing the link of the Stack Overflow question here to help other community members who might be looking for answer to similar issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.