Reputation: 1
I have used OpenTelemetry to instrument an ASP.NET Core project and gather logs and traces. After collection both should be sent to an Azure Application Insights resource for storage and querying. The issue is that while both logs and traces are succesfully captured and displayed on the console, only the logs are being sent to Application Insights. No matter what changes I make to the configuration I can't seem to get the traces to show up in Azure. I would love to see even a single trace with a correlationId in the traces table. Does anyone have an idea why traces are not being sent to Azure?
See OpenTelemetry configuration below.
private void ConfigureOpenTelemetry(IServiceCollection services)
{
var applicationInsightsConnectionString = "valid-connection-string";
var serviceName = "backend-service-name"
services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(serviceName))
.UseAzureMonitor(options =>
{
options.ConnectionString = applicationInsightsConnectionString;
})
.WithTracing(builder =>
{
builder.AddSource("ActivitySourceName");
builder.AddAspNetCoreInstrumentation();
builder.AddConsoleExporter();
builder.AddAzureMonitorTraceExporter(o => o.ConnectionString = applicationInsightsConnectionString);
});
services.AddLogging(logging =>
{
logging.AddOpenTelemetry(options =>
{
options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName));
options.AddConsoleExporter();
options.AddAzureMonitorLogExporter(o => o.ConnectionString = applicationInsightsConnectionString);
});
});
}
I have tried countless variations of configuring OpenTelemetry and triple-checked to see if my config was the same as in the docs and example applications
Upvotes: 0
Views: 316
Reputation: 7367
I have tried with .NET Core 8 and able to see the traces, Dependencies and requests in the Application Insights with your code and the below configuration.
My appsettings.json
file:
{
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Error"
}
},
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
The logs which are shown in Local Console are shown with different parameters in Application Insights.
Local:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5161
LogRecord.Timestamp: 2025-01-10T10:28:30.0781350Z
LogRecord.CategoryName: Microsoft.Hosting.Lifetime
LogRecord.Severity: Info
LogRecord.SeverityText: Information
LogRecord.FormattedMessage: Now listening on: http://localhost:5161
LogRecord.Body: Now listening on: {address}
LogRecord.Attributes (Key:Value):
address: http://localhost:5161
OriginalFormat (a.k.a Body): Now listening on: {address}
LogRecord.EventId: 14
LogRecord.EventName: ListeningOnAddress
Resource associated with LogRecord:
service.name: New Service Name
service.instance.id: b7bffadb-3981-4b27-bb69-e95644b8321a
telemetry.sdk.name: opentelemetry
telemetry.sdk.language: dotnet
telemetry.sdk.version: 1.10.0
Transaction Search
:
Service Instance ID is shown as RoleInstance
.
.csproj.cs
file : <ItemGroup>
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />
</ItemGroup>
Also refer this MSDoc for more details.
Upvotes: 0