microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.7k stars 3.22k forks source link

Feature Request: Add Metrics Support via .NET's Built-In `Meter` to Semantic Kernel Library #1966

Closed GalRabin closed 1 year ago

GalRabin commented 1 year ago

Hello Semantic Kernel team,

I would like to propose a feature to enhance the Semantic Kernel library. The proposal is to add support for custom Meter objects from the System.Diagnostics.Metrics namespace in .NET, which is the standard metrics API.

The use case for this feature is to allow library users to capture and analyze metrics in their preferred metrics backend (Prometheus, Jaeger, etc.) via OpenTelemetry or other telemetry libraries. This would enable users to monitor performance, identify issues early, and gain insights into how their applications are being used.

To implement this feature, I suggest that the Builder class (or whatever class is used to configure the Semantic Kernel library) includes a withMeter(Meter meter) method, where Meter is an instance of System.Diagnostics.Metrics.Meter. This will allow users to pass in a custom Meter during configuration.

The code could look something like this:

var meter = new Meter("MyApplication", "1.0.0");
var builder = new SemanticKernelBuilder()
    .withMeter(meter)
    // other configuration...
    .build();

In the Semantic Kernel library code, you would use this Meter to create and record metrics:

var counter = this.meter.CreateCounter<long>("my-counter");

// In relevant parts of the library:
counter.Add(1);

This feature would not impose any specific telemetry library or backend on Semantic Kernel users. Instead, it would provide the flexibility for users to choose how they want to capture, export, and analyze metrics.

Thank you for considering this feature request.

dmytrostruk commented 1 year ago

Hi @GalRabin , thank you for your proposal. This issue already exists and already handled using the same approach. Please check the following links.

Issue: https://github.com/microsoft/semantic-kernel/issues/1651

PR: https://github.com/microsoft/semantic-kernel/pull/1905