Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions playground/Stress/Stress.TelemetryService/CounterMetrics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.Metrics;

namespace Stress.TelemetryService;

public class CounterMetrics(ILogger<CounterMetrics> logger, IMeterFactory meterFactory) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
logger.LogInformation("Starting CounterMetrics");

var meter = meterFactory.Create("CounterMetrics");
var counter = meter.CreateCounter<int>(
name: "run.done.new.count",
description: "Count of new done run",
unit: "count");

for (var i = 0; i < 1000000; i++)
{
counter.Add(1);
await Task.Delay(20, cancellationToken);
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting the delay duration (20 milliseconds) into a named constant could enhance readability and maintainability.

Suggested change
await Task.Delay(20, cancellationToken);
await Task.Delay(DelayDurationMilliseconds, cancellationToken);

Copilot uses AI. Check for mistakes.
}
}
}
2 changes: 2 additions & 0 deletions playground/Stress/Stress.TelemetryService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<TelemetryStresser>();
builder.Services.AddHostedService<GaugeMetrics>();
builder.Services.AddHostedService<CounterMetrics>();

builder.AddServiceDefaults();
builder.Logging.SetMinimumLevel(LogLevel.Trace);
Expand All @@ -14,6 +15,7 @@
.WithMetrics(metrics =>
{
metrics.AddMeter("GaugeMetrics");
metrics.AddMeter("CounterMetrics");
});

var app = builder.Build();
Expand Down