Skip to content

Commit

Permalink
add tracing example
Browse files Browse the repository at this point in the history
  • Loading branch information
area363 committed Jul 11, 2024
1 parent 4e9d8dd commit 1973000
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<PackageReference Include="GraphQL.Client" Version="5.1.1" />
<PackageReference Include="GraphQL.Client.Serializer.SystemTextJson" Version="5.1.1" />
<PackageReference Include="Destructurama.Attributed" Version="2.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.9.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="Pyroscope" Version="0.8.14" />
<PackageReference Include="Pyroscope.OpenTelemetry" Version="0.2.0" />
<PackageReference Include="Sentry.Serilog" Version="3.23.0" />
<PackageReference Include="Sentry" Version="3.23.0" />
<PackageReference Include="Sentry.AspNetCore.Grpc" Version="3.22.0" />
Expand All @@ -42,6 +48,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
27 changes: 26 additions & 1 deletion NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
using OpenTelemetry;
using OpenTelemetry.Metrics;
using Nekoyume;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace NineChronicles.Headless.Executable
{
Expand Down Expand Up @@ -474,15 +476,38 @@ IActionLoader MakeSingleActionLoader()
MaxTransactionPerBlock = headlessConfig.MaxTransactionPerBlock
};
var arenaMemoryCache = new StateMemoryCache();
string otlpEndpoint = Environment.GetEnvironmentVariable("OPTL_ENDPOINT") ?? "http://localhost:4317";
hostBuilder.ConfigureServices(services =>
{
services.AddSingleton(_ => standaloneContext);
services.AddSingleton<ConcurrentDictionary<string, ITransaction>>();
services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(
serviceName: Assembly.GetEntryAssembly()?.GetName().Name ?? "NineChronicles.Headless",
serviceVersion: Assembly.GetEntryAssembly()?.GetName().Version?.ToString(),
serviceInstanceId: Environment.MachineName
).AddAttributes(new Dictionary<string, object>
{
{ "deployment.environment", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Unknown" },
}))
.WithMetrics(
builder => builder
.AddMeter("NineChronicles")
.AddPrometheusExporter());
.AddPrometheusExporter())
.WithTracing(
builder => builder
.AddSource("Lib9c.Action.HackAndSlash")
.AddSource("Libplanet.Action.State")
.AddSource("Libplanet.Blockchain.BlockChainStates")
//.AddAspNetCoreInstrumentation()
.AddGrpcClientInstrumentation()
.AddConsoleExporter()
.AddProcessor(new Pyroscope.OpenTelemetry.PyroscopeSpanProcessor())
.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(otlpEndpoint, UriKind.Absolute);
})
);

// worker
if (arenaParticipantsSync)
Expand Down
2 changes: 2 additions & 0 deletions NineChronicles.Headless/NineChronicles.Headless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.11" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NRedisStack" Version="0.9.0" />
<PackageReference Include="Pyroscope" Version="0.8.14" />
<PackageReference Include="Sentry" Version="3.23.0" />
<PackageReference Include="Sentry.AspNetCore.Grpc" Version="3.22.0" />
<PackageReference Include="Sentry.DiagnosticSource" Version="3.22.0" />
Expand All @@ -64,6 +65,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 1973000

Please sign in to comment.