arcus.observability
arcus.observability copied to clipboard
feat(otel): use new observability api for otel/serilog implementations
Use a new interface called IObservability to place traces/metrics away from the ILogger interface. This is the result of the discussion #587 . This PR provides an implementation for both OpenTelemetry and Serilog to showcase in a single go the possible abstraction and to ease the migration from Serilog ➡️ OpenTelemetry.
No feature documentation updates are made yet, as this will require a refactoring exercise by itself.
Deploy Preview for arcus-observability canceled.
| Name | Link |
|---|---|
| Latest commit | d018f16ae9214a410d482ad8208d35936e391788 |
| Latest deploy log | https://app.netlify.com/projects/arcus-observability/deploys/690457e01daccf0008959e1c |
I'm trying to wrap my head around this to see how I could use / play with it.
I'm trying to wrap my head around this to see how I could use / play with it.
Ok, I created a small console app which looks like this:
internal class Program
{
static void Main(string[] args)
{
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddOpenTelemetry().UseAzureMonitor(o => o.ConnectionString = "InstrumentationKey=....").UseObservability();
builder.Services.AddHostedService<Worker>();
var app = builder.Build();
app.Run();
}
}
public class Worker : BackgroundService
{
private readonly IObservability _observability;
public Worker(IObservability observability)
{
_observability = observability;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var workerMetric = _observability.RecordMetric("worker_stuff");
while (!stoppingToken.IsCancellationRequested)
{
Console.WriteLine($"Worker running at: {DateTime.Now}");
workerMetric.WithValue(Random.Shared.Next(1, 15));
await Task.Delay(1000, stoppingToken);
}
}
}
Metric is being registered