feat: add zipkin exporter and additional tracing options
This commit is contained in:
parent
157dbbc2f5
commit
6a9e1c338e
3 changed files with 64 additions and 38 deletions
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Npgsql;
|
||||
using OpenTelemetry.Logs;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Resources;
|
||||
|
@ -34,11 +35,12 @@ var loggerFactory = LoggerFactory.Create(loggingBuilder =>
|
|||
});
|
||||
|
||||
var configuration = builder.Configuration;
|
||||
|
||||
Action<ResourceBuilder> resourceBuilderAction = r => r
|
||||
if (configuration.GetValue<bool>("Tracing:Enabled"))
|
||||
{
|
||||
Action<ResourceBuilder> resourceBuilderAction = r => r
|
||||
.AddService("Continuity", serviceInstanceId: Environment.MachineName);
|
||||
|
||||
builder.Services.AddOpenTelemetry()
|
||||
builder.Services.AddOpenTelemetry()
|
||||
.ConfigureResource(resourceBuilderAction)
|
||||
.WithTracing(tracing =>
|
||||
{
|
||||
|
@ -47,6 +49,7 @@ builder.Services.AddOpenTelemetry()
|
|||
tracing.AddMassTransitInstrumentation();
|
||||
tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true);
|
||||
tracing.AddHttpClientInstrumentation();
|
||||
tracing.AddNpgsql();
|
||||
})
|
||||
.WithMetrics(metrics =>
|
||||
{
|
||||
|
@ -54,26 +57,36 @@ builder.Services.AddOpenTelemetry()
|
|||
metrics.AddHttpClientInstrumentation();
|
||||
});
|
||||
|
||||
builder.Logging.AddOpenTelemetry(logging =>
|
||||
{
|
||||
builder.Logging.AddOpenTelemetry(logging =>
|
||||
{
|
||||
var resourceBuilder = ResourceBuilder.CreateDefault();
|
||||
resourceBuilderAction(resourceBuilder);
|
||||
logging.SetResourceBuilder(resourceBuilder);
|
||||
logging.IncludeFormattedMessage = true;
|
||||
logging.IncludeScopes = true;
|
||||
});
|
||||
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging =>
|
||||
logging.AddOtlpExporter(options => options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty)));
|
||||
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics =>
|
||||
metrics.AddOtlpExporter(options => options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty)));
|
||||
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing =>
|
||||
tracing.AddOtlpExporter(options => options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty)));
|
||||
});
|
||||
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging =>
|
||||
{
|
||||
logging.AddOtlpExporter(options =>
|
||||
{
|
||||
options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty);
|
||||
});
|
||||
});
|
||||
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics =>
|
||||
{
|
||||
metrics.AddOtlpExporter(options =>
|
||||
options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty));
|
||||
});
|
||||
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing =>
|
||||
{
|
||||
tracing.AddZipkinExporter(options =>
|
||||
options.Endpoint = new Uri(configuration["Zipkin:Endpoint"] ?? string.Empty));
|
||||
tracing.AddOtlpExporter(options => options.Endpoint = new Uri(configuration["OTLP:Endpoint"] ?? string.Empty));
|
||||
});
|
||||
}
|
||||
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
|
||||
builder.Services.AddSingleton<CharacterStatsMappingConfiguration>(
|
||||
JsonSerializer.Deserialize<CharacterStatsMappingConfiguration>(
|
||||
File.ReadAllText("config/character-stats.mapping.json")) ?? throw new InvalidOperationException());
|
||||
|
||||
builder.Services.AddDbContextPool<WonderkingContext>(o =>
|
||||
{
|
||||
|
@ -82,6 +95,10 @@ builder.Services.AddDbContextPool<WonderkingContext>(o =>
|
|||
.EnableSensitiveDataLogging().UseLazyLoadingProxies().UseLoggerFactory(loggerFactory);
|
||||
});
|
||||
|
||||
builder.Services.AddSingleton<CharacterStatsMappingConfiguration>(
|
||||
JsonSerializer.Deserialize<CharacterStatsMappingConfiguration>(
|
||||
File.ReadAllText("config/character-stats.mapping.json")) ?? throw new InvalidOperationException());
|
||||
|
||||
builder.Services.AddSingleton<ILoggerFactory>(loggerFactory);
|
||||
builder.Services.AddSingleton<PacketDistributorService>();
|
||||
builder.Services.AddSingleton<ItemObjectPoolService>();
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
<PackageReference Include="NetCoreServer" Version="8.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0-rc.2"/>
|
||||
<PackageReference Include="Npgsql.OpenTelemetry" Version="7.0.6" />
|
||||
<PackageReference Include="Nullable.Extended.Analyzer" Version="1.10.4539">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
@ -92,6 +93,7 @@
|
|||
<PackageReference Include="OpenTelemetry" Version="1.7.0-alpha.1" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0-alpha.1" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1" />
|
||||
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.7.0-alpha.1" />
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.8" />
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.3" />
|
||||
|
|
|
@ -13,7 +13,9 @@ services:
|
|||
- DB:Username=continuity
|
||||
- DB:Password=continuity
|
||||
- Game:Data:Path=/app/data/
|
||||
- Tracing:Enabled=true
|
||||
- OTLP:Endpoint=http://jaeger:4317
|
||||
- Zipkin:Endpoint=http://zipkin:9411/api/v2/spans
|
||||
networks:
|
||||
- continuity
|
||||
ports:
|
||||
|
@ -68,11 +70,16 @@ services:
|
|||
- 14250:14250
|
||||
- 14268:14268
|
||||
- 14269:14269
|
||||
- 9411:9411
|
||||
environment:
|
||||
- COLLECTOR_ZIPKIN_HOST_PORT=:9411
|
||||
- COLLECTOR_OTLP_ENABLED=true
|
||||
|
||||
zipkin:
|
||||
image: openzipkin/zipkin
|
||||
ports:
|
||||
- 9411:9411
|
||||
networks:
|
||||
- continuity
|
||||
|
||||
networks:
|
||||
continuity:
|
||||
|
||||
|
|
Loading…
Reference in a new issue