Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add open telemetry #166

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 8 additions & 1 deletion 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 @@ -104,11 +106,16 @@
// The following line enables Application Insights telemetry collection.
var appInsightsOptions = new ApplicationInsightsServiceOptions
{
ConnectionString = configuration["ApplicationInsights:ConnectionString"],
ConnectionString = appInsightsConnectionString,
EnableAdaptiveSampling = false
};
builder.Services.AddApplicationInsightsTelemetry(options: appInsightsOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the application insights telemetry to avoid double logging of everything.


// 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<>));
CommandHandlersSetup.AddCommandHandlers(builder.Services, typeof(ICommandHandler<,>));
Expand Down