open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.17k stars 752 forks source link

Ability to export Prometheus Metrics on a function project #4283

Open lbargery opened 1 year ago

lbargery commented 1 year ago

Feature Request

Is your feature request related to a problem?

My problem is that I'd like to be able to have prometheus scrape metrics from an HTTP endpoint on my functions project. The current middleware won't work for this since that's very server orientated. I imagine I will need to add a HTTP function endpoint to my functions project and write the metrics in. However, because so many of the classes are internal, this isn't possible.

Describe the solution you'd like:

I think this could be solve by either making the classes public (which I appreciate you might not want to do!) or by making an extension method of some form which operates on the HttpRequestData. Something a bit like this though can probably use dependency injection much better than passing all services.

public class Metrics
{
    private readonly IServiceProvider _serviceProvider;

    public Metrics(IServiceProvider serviceProvider)
    {
        _serviceProvider = serviceProvider;
    }

    [Function("/metrics")]
    public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req,
        FunctionContext executionContext)
    {
        return req.WritePrometheusMetrics(_serviceProvider);

    }
}

Describe alternatives you've considered.

I could currently use reflection to hack around this? Not sure if anything else I could do.

Additional Context

Happy to have a go at implementing this myself if the general functionality request is okay.

RohitRanjanMS commented 8 months ago

Hi @lbargery, we are actively working on a feature to enable OpenTelemetry support, ETA April/May. Here's our https://github.com/Azure/azure-functions-host/issues/9273. I would also like to understand your scenario better, are you looking to export ASP.NetCore metrics or your own custom metrics? Please transfer this issue over to the azure-functions-host repo.

RohitRanjanMS commented 8 months ago

@BigMorty FYI