Skip to content

Commit

Permalink
Merge pull request #1872 from moreal/open-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal authored Feb 2, 2023
2 parents a2caa4a + 4bb0c7a commit a22318b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions NineChronicles.Headless/ActionEvaluationPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.Metrics;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand Down Expand Up @@ -66,6 +67,12 @@ public ActionEvaluationPublisher(
_context = context;
_sentryTraces = sentryTraces;

var meter = new Meter("NineChronicles");
meter.CreateObservableGauge(
"ninechronicles_rpc_clients_count",
() => this.GetClients().Count,
description: "Number of RPC clients connected.");

ActionEvaluationHub.OnClientDisconnected += RemoveClient;
}

Expand Down
2 changes: 2 additions & 0 deletions NineChronicles.Headless/GraphQLService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
// Prints
app.UseMiddleware<GraphQLSchemaMiddleware<StandaloneSchema>>("/schema.graphql");

app.UseOpenTelemetryPrometheusScrapingEndpoint();

// /ui/playground 옵션을 통해서 Playground를 사용할 수 있습니다.
app.UseGraphQLPlayground();
}
Expand Down
9 changes: 9 additions & 0 deletions NineChronicles.Headless/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Nekoyume.Action;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using Sentry;

namespace NineChronicles.Headless
Expand Down Expand Up @@ -79,6 +81,13 @@ RpcNodeServiceProperties properties
options.MaxReceiveMessageSize = null;
});
services.AddMagicOnion();
services.AddOpenTelemetry()
.WithMetrics(
builder => builder
.AddMeter("NineChronicles")
.AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation()
.AddPrometheusExporter());
services.AddSingleton(provider =>
{
StandaloneContext? ctx = provider.GetRequiredService<StandaloneContext>();
Expand Down
6 changes: 6 additions & 0 deletions NineChronicles.Headless/NineChronicles.Headless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<PackageReference Include="Sentry.DiagnosticSource" Version="3.22.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="GraphQL" Version="4.7.1" />
<PackageReference Include="OpenTelemetry" Version="1.4.0-rc.2" />
<PackageReference Include="OpenTelemetry.Api" Version="1.4.0-rc.2" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.4.0-rc.2" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.4.0-rc.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.11" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.1.0-beta.3" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.49.0.57237">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
14 changes: 14 additions & 0 deletions NineChronicles.Headless/NineChroniclesNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Linq;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.Metrics;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
Expand Down Expand Up @@ -278,6 +279,19 @@ StandaloneContext context
txQuotaPerSigner: properties.TxQuotaPerSigner
);
service.ConfigureContext(context);
var meter = new Meter("NineChronicles");
meter.CreateObservableGauge(
"ninechronicles_tip_index",
() => service.BlockChain.Tip.Index,
description: "The tip block's index.");
meter.CreateObservableGauge(
"ninechronicles_staged_txids_count",
() => service.BlockChain.GetStagedTransactionIds().Count,
description: "Number of staged transactions.");
meter.CreateObservableGauge(
"ninechronicles_subscriber_addresses_count",
() => context.AgentAddresses.Count);

return service;
}

Expand Down

0 comments on commit a22318b

Please sign in to comment.