Skip to content

Commit

Permalink
Add Azure Monitor OpenTelemetry package
Browse files Browse the repository at this point in the history
  • Loading branch information
0GiS0 committed Feb 19, 2024
1 parent 4d75f44 commit a0ca33f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OpenTelemetry.Instrumentation.AspNetCore;
using tour_of_heroes_api.Interfaces;
using tour_of_heroes_api.Repositories;
using Azure.Monitor.OpenTelemetry.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -24,7 +25,7 @@
/********************************** Application Insights ****************************************/
/************************************************************************************************/

builder.Services.AddApplicationInsightsTelemetry(); //You need ApplicationInsights.ConnectionString in your appsettings.json
// builder.Services.AddApplicationInsightsTelemetry(); //You need ApplicationInsights.ConnectionString in your appsettings.json

/************************************************************************************************
********************************** Open Telemetry configuration *********************************
Expand All @@ -42,15 +43,15 @@
resourceBuilder.AddService(serviceName);
options.SetResourceBuilder(resourceBuilder);

// options.AddConsoleExporter();
options.AddConsoleExporter();
options.AddOtlpExporter(); //This will, by default, send traces using gRPC to http://localhost:4317

});

builder.Services.AddHttpLogging(o => o.LoggingFields = HttpLoggingFields.All);

builder.Services.AddOpenTelemetry()
// .UseAzureMonitor() //https://learn.microsoft.com/es-es/azure/azure-monitor/app/opentelemetry-configuration?tabs=aspnetcore
.UseAzureMonitor() //https://learn.microsoft.com/es-es/azure/azure-monitor/app/opentelemetry-configuration?tabs=aspnetcore
.ConfigureResource(resource => resource.AddService(serviceName))
.WithTracing(tracing =>
{
Expand All @@ -61,7 +62,7 @@

tracing.AddOtlpExporter();

// tracing.AddConsoleExporter();
tracing.AddConsoleExporter();

})
.WithMetrics(metrics =>
Expand Down
3 changes: 3 additions & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=3faddc52-30e5-46dc-801f-c2a46c197ade;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/"
},
"AzureMonitor": {
"ConnectionString": "InstrumentationKey=b896b53e-acd7-4da6-9993-1303482cbbce;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/"
},
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion tour-of-heroes-api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.6.0-beta.3" />

<!-- Exporters -->
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.0.0" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.1.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.6.0-rc.1" />
Expand Down

0 comments on commit a0ca33f

Please sign in to comment.