Skip to content

Commit

Permalink
feat: add open telemetry (#166)
Browse files Browse the repository at this point in the history
* feat: add open telemetry
#162

* removed appinsights
  • Loading branch information
ashukequinor authored Nov 19, 2024
1 parent e53a3cc commit e18150b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Oplog.Api/Oplog.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.1" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.5" />
Expand Down
13 changes: 6 additions & 7 deletions src/Oplog.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Oplog.Persistence.Repositories;
using System;
using System.Net.Http;
using Azure.Monitor.OpenTelemetry.AspNetCore;

var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
Expand All @@ -30,6 +31,7 @@
var clientId = configuration["AzureAd:ClientId"];
var clientSecret = configuration["AzureAd:ClientSecret"];
var tenantId = configuration["AzureAd:TenantId"];
var appInsightsConnectionString = configuration["ApplicationInsights:ConnectionString"];

if (!builder.Environment.IsDevelopment())
{
Expand Down Expand Up @@ -101,13 +103,10 @@
builder.Services.AddScoped<IIndexSearchClient, IndexSearchClient>();
builder.Services.AddTransient<ISearchLogsQueries, SearchLogsQueries>();

// The following line enables Application Insights telemetry collection.
var appInsightsOptions = new ApplicationInsightsServiceOptions
{
ConnectionString = configuration["ApplicationInsights:ConnectionString"],
EnableAdaptiveSampling = false
};
builder.Services.AddApplicationInsightsTelemetry(options: appInsightsOptions);
// Add OpenTelemetry and configure it to use Azure Monitor.
builder.Services.AddOpenTelemetry().UseAzureMonitor(options => {
options.ConnectionString = appInsightsConnectionString;
});

//Add command handlers
CommandHandlersSetup.AddCommandHandlers(builder.Services, typeof(ICommandHandler<>));
Expand Down

0 comments on commit e18150b

Please sign in to comment.