change: Add OpenTelemetry
This commit is contained in:
@@ -17,7 +17,7 @@ COPY ["src/SplashPage.Core", "src/SplashPage.Core"]
|
||||
COPY ["src/SplashPage.EntityFrameworkCore", "src/SplashPage.EntityFrameworkCore"]
|
||||
COPY ["src/SplashPage.Web.Mvc/App_Data", "src/SplashPage.Web.Mvc/App_Data"]
|
||||
WORKDIR "/src/src/SplashPage.Web.Host"
|
||||
RUN dotnet publish -c Debug -o /publish --no-restore
|
||||
RUN dotnet publish -c Release -o /publish --no-restore
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0
|
||||
EXPOSE 80
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="OpenTelemetry" Version="1.14.0" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.11" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
|
||||
<PackageReference Include="Npgsql.OpenTelemetry" Version="8.0.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
||||
<PackageReference Include="MyCSharp.HttpUserAgentParser.AspNetCore" Version="3.0.12-g2db20cc097" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -15,9 +15,14 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MyCSharp.HttpUserAgentParser.DependencyInjection;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Logs;
|
||||
using System.Collections.Generic;
|
||||
using Npgsql;
|
||||
|
||||
namespace SplashPage.Web.Host.Startup
|
||||
{
|
||||
@@ -67,6 +72,48 @@ namespace SplashPage.Web.Host.Startup
|
||||
// Swagger - Enable this line and the related lines in Configure method to enable swagger UI
|
||||
ConfigureSwagger(services);
|
||||
|
||||
|
||||
var customer = Environment.GetEnvironmentVariable(SplashPageConsts.EnvCustomer) ?? "Default";
|
||||
|
||||
#if RELEASE
|
||||
services.AddOpenTelemetry()
|
||||
.ConfigureResource(resource =>
|
||||
{
|
||||
resource.AddService($"{customer}-OSB");
|
||||
resource.AddAttributes(new Dictionary<string, object>
|
||||
{
|
||||
// read ASP.NET Core environment or hard-code your env name
|
||||
["deployment.environment"] = _hostingEnvironment.EnvironmentName ?? "Development"
|
||||
});
|
||||
}) // your app name
|
||||
.WithTracing(tracing => tracing
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddNpgsql()
|
||||
.AddEntityFrameworkCoreInstrumentation()
|
||||
.AddOtlpExporter(otlpOptions =>
|
||||
{
|
||||
otlpOptions.Endpoint = new Uri("http://172.21.4.201:4317"); // or your collector
|
||||
}))
|
||||
.WithMetrics(metrics =>
|
||||
{
|
||||
metrics.AddMeter("Npgsql");
|
||||
metrics.AddMeter("Microsoft.AspNetCore.Hosting");
|
||||
metrics.AddMeter("Microsoft.AspNetCore.Server.Kestrel");
|
||||
metrics.AddMeter("System.Net.Http");
|
||||
metrics.AddMeter("System.Runtime"); // this is the "runtime" metrics now
|
||||
metrics.AddHttpClientInstrumentation();
|
||||
metrics.AddAspNetCoreInstrumentation();
|
||||
metrics.AddOtlpExporter();
|
||||
metrics.AddRuntimeInstrumentation();
|
||||
//metrics.AddConsoleExporter();
|
||||
metrics.AddMeter("Microsoft.AspNetCore.Hosting");
|
||||
metrics.AddMeter("Microsoft.AspNetCore.Server.Kestrel");
|
||||
metrics.AddMeter("System.Net.Http");
|
||||
metrics.AddMeter("System.Runtime"); // Runtime metrics like CPU/memory
|
||||
|
||||
});
|
||||
#endif
|
||||
// Configure Abp and Dependency Injection
|
||||
services.AddAbpWithoutCreatingServiceProvider<SplashPageWebHostModule>(
|
||||
// Configure Log4Net logging
|
||||
|
||||
Reference in New Issue
Block a user