Skip to content

Commit

Permalink
Add basic tracing from OpenTelemetry
Browse files Browse the repository at this point in the history
Note: Currently, the traces are being exported to the console, but that can be changed as needed.

--ECL
  • Loading branch information
Enkidu93 committed Sep 14, 2023
1 parent 1ed350f commit ac2ac2a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Serval.ApiServer/Serval.ApiServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.1-beta.1" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/Serval.ApiServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ public void ConfigureServices(IServiceCollection services)
};
});
}

services
.AddOpenTelemetry()
.WithTracing(builder =>
{
builder.AddAspNetCoreInstrumentation().AddConsoleExporter();
builder.AddHttpClientInstrumentation().AddConsoleExporter();
});
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down
3 changes: 3 additions & 0 deletions src/Serval.ApiServer/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
global using Microsoft.Extensions.Diagnostics.HealthChecks;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.IdentityModel.Tokens;
global using NJsonSchema;
global using NJsonSchema.Generation;
global using NSwag;
global using NSwag.AspNetCore;
global using NSwag.Generation.Processors.Security;
global using OpenTelemetry;
global using OpenTelemetry.Trace;
global using Serval.Shared.Contracts;
global using Serval.Shared.Controllers;
global using Serval.Shared.Models;
Expand Down

0 comments on commit ac2ac2a

Please sign in to comment.