Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet 6 Configuration #720

Open
hughesjs opened this issue Nov 12, 2021 · 4 comments
Open

Dotnet 6 Configuration #720

hughesjs opened this issue Nov 12, 2021 · 4 comments

Comments

@hughesjs
Copy link

Dotnet 6 does away with the need for complex nested lambdas etc for configuration (let's be real, that was always a terrible API).

The new hotness WebApplication rather than Host or WebHost is great. Unfortunately, the existing ConfigureMetricsWithDefaults() doesn't work with this pattern at all.

We need to update things to work better with dotnet 6

@krzysiek-b
Copy link

+1

@Simonl9l
Copy link

@hughesjs & @krzysiek-b - What no Program or Startup!

Just in case you have not figured it out - this seems to work:

var builder = WebApplication.CreateBuilder();

builder.Services
    .AddMetrics(metrics)
    .AddAppMetricsSystemMetricsCollector()
    .AddAppMetricsCollectors();
           
builder.Host
    .ConfigureMetrics(builder =>
        {
            builder.Configuration.Configure(options =>
                {
                    options.DefaultContextLabel = "default";
                 });
         })
    .UseMetrics(options =>
        {
            options.EndpointOptions = endpointsOptions =>
                {
                    endpointsOptions.MetricsTextEndpointOutputFormatter =
                            new MetricsPrometheusTextOutputFormatter();
                };
        });
            
var web = builder.Build();
web.Urls.Add($"http://localhost:{port}");
web.UseMetricsTextEndpoint();
await web.RunAsync(_source.Token);

@hughesjs
Copy link
Author

Yeah, I got it to work, but that's not really my point. A large part of the changes to dotnet 6 startup were driven by a desire to simplify things and reduce the need for chains of nested lamdas.

I feel like that's something we should aspire to support.

@gjemp
Copy link

gjemp commented Apr 28, 2022

@hughesjs can u share some example how did you get it working and for some reasons the metrics endpoint started to serve the data in binary format when i started to use AsPrometheusPlainText or AsPrometheusProtobuf as explained here: https://www.app-metrics.io/reporting/reporters/prometheus/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants