Skip to content

Commit

Permalink
Implement opentelemetry (#36)
Browse files Browse the repository at this point in the history
* create solution folder for misc files to make accessible in VS & Rider

* add basic opentelemetry implementation

* remove extra whitespace

Co-authored-by: Brendan Enrick <[email protected]>
  • Loading branch information
edmistond and benrick authored Nov 29, 2022
1 parent 5462eef commit fd6ea54
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0" />
<PackageVersion Include="EFCore.NamingConventions" Version="7.0.0" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.3.1" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.3.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.9" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.9" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.9" />
<PackageVersion Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.0.0-rc9.9" />

</ItemGroup>
<ItemGroup>
<PackageVersion Include="AutoFixture" Version="4.17.0" />
Expand Down
10 changes: 10 additions & 0 deletions Smilodon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActivityPub.Domain", "src\A
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{46FC91AA-B4F6-4339-A414-5126474048C6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{98B687E0-157E-4EF0-8482-6E6EDF46E034}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
Directory.Packages.props = Directory.Packages.props
nuget.config = nuget.config
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
24 changes: 23 additions & 1 deletion src/WebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
using Microsoft.EntityFrameworkCore;
using OpenTelemetry.Exporter;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Smilodon.Infrastructure.Persistence;
using Smilodon.WebApp.Api.Admin;
using Smilodon.WebApp.Api.Webfinger;

var builder = WebApplication.CreateBuilder(args);

// this should really be in the app config instead...
const string serviceName = "Smilodon.WebApp";
const string serviceVersion = "0.0.1";

// Add services to the container.

builder.Services.AddOpenTelemetryTracing(tracerProviderBuilder =>
{
tracerProviderBuilder
.AddConsoleExporter()
.AddOtlpExporter(opt =>
{
opt.Protocol = OtlpExportProtocol.HttpProtobuf;
})
.AddSource(serviceName)
.SetResourceBuilder(ResourceBuilder.CreateDefault()
.AddService(serviceName: serviceName, serviceVersion: serviceVersion))
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation()
.AddSqlClientInstrumentation();
});

builder.Services.AddControllersWithViews();

// Add the database context to the DI container
Expand All @@ -15,7 +38,6 @@
.UseNpgsql("Host=localhost; Database=smilodon; User Id=smilodon; Password=smilodon;")
.UseSnakeCaseNamingConvention());


var app = builder.Build();

// Configure the HTTP request pipeline.
Expand Down
11 changes: 10 additions & 1 deletion src/WebApp/WebApp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand All @@ -9,6 +9,15 @@
<RootNamespace>Smilodon.WebApp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry.Exporter.Console" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup>
Expand Down

0 comments on commit fd6ea54

Please sign in to comment.