admin管理员组文章数量:1125885
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
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
Share Improve this question asked 2 days ago Jasper KeijzerJasper Keijzer 11 bronze badge New contributor Jasper Keijzer is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 7 | Show 2 more comments1 Answer
Reset to default 0I 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
:
- Same log is shown in Application Insights as Trace.
Service Instance ID is shown as RoleInstance
.
- My
.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.
本文标签: cOpenTelemetry traces not being sent to AzureStack Overflow
版权声明:本文标题:c# - OpenTelemetry traces not being sent to Azure - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736643130a1946042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
builder.AddAzureMonitorTraceExporter(o => o.ConnectionString = applicationInsightsConnectionString);
You could try setting theDiagnostics
parameter ofAzureMonitorExporterOptions
to see what's actually going on – Panagiotis Kanavos Commented 2 days agoActivity
at all? From this config it seems only ASP.NET Core is instrumented so you'll only see spans generated by ASP.NET Core in response to requests. – Panagiotis Kanavos Commented 2 days agoActivity
in my application but haven't included that code because I figured it wasn't relevant to the configuration. I can see both ASP.NET Core and custom spans in the console when using the ConsoleExporter. Thanks for theDiagnostics
suggestion, I'll try to play around with that and see if I can get more info – Jasper Keijzer Commented 2 days ago