Metrics interceptor and middleware for IceRPC
$ dotnet add package IceRpc.MetricsIceRpc.Metrics provides an IceRPC interceptor and an IceRPC middleware.
The metrics interceptor instruments invocations using the Meter API, while the metrics middleware instruments dispatches using the same API.
You can display the collected measurements with dotnet-counters and other tools.
Source code | Package | Example | API reference | Interceptor documentation | Middleware documentation
// Client application
using IceRpc;
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));
// Create an invocation pipeline and install the metrics interceptor.
Pipeline pipeline = new Pipeline().UseMetrics().Into(connection);
// Server application
using IceRpc;
// Create a router (dispatch pipeline) and install the metrics middleware.
Router router = new Router().UseMetrics().Map<...>(...);
// Client application
using IceRpc;
using IceRpc.Extensions.DependencyInjection;
var hostBuilder = Host.CreateDefaultBuilder(args);
hostBuilder.ConfigureServices(services =>
services
.AddIceRpcClientConnection(new Uri("icerpc://localhost"))
.AddIceRpcInvoker(builder =>
builder
// Add the metrics interceptor to the invocation pipeline.
.UseMetrics()
.Into<ClientConnection>()));
using var host = hostBuilder.Build();
host.Run();
// Server application
using IceRpc;
using IceRpc.Extensions.DependencyInjection;
var hostBuilder = Host.CreateDefaultBuilder(args);
hostBuilder.ConfigureServices(services =>
services
.AddIceRpcServer(builder =>
builder
// Add the metrics middleware to the dispatch pipeline.
.UseMetrics()
.Map<...>()));
using var host = hostBuilder.Build();
host.Run();