feat: adapt to enabled observability features.

This commit is contained in:
redglow
2026-07-29 12:49:42 +02:00
parent b3073ee1ba
commit ce6cfaccb2
4 changed files with 27 additions and 9 deletions
+12 -2
View File
@@ -1,18 +1,29 @@
using System;
using System.Diagnostics.Metrics;
using GodotHostTest.Interfaces;
using Microsoft.Extensions.Logging;
using OwofGames.GodotHost;
using OwofGames.GodotHost.Observability;
using OwofGames.GodotLume;
using R3;
namespace GodotHostTest.Game.Metrics;
public class MetricsHandler(IMeterFactory meterFactory, ITargetEventBus targetEventBus) : IHostLifetime
public class MetricsHandler(
ILogger<MetricsHandler> logger,
IOptional<IMeterFactory> meterFactoryWrapper,
ITargetEventBus targetEventBus) : IHostLifetime
{
private IDisposable? _disposables;
public void Startup()
{
if (!meterFactoryWrapper.TryGet(out var meterFactory))
{
logger.LogWarning("Metrics not enabled, cannot start local metrics");
return;
}
// create meter
var meter = meterFactory.Create();
@@ -33,6 +44,5 @@ public class MetricsHandler(IMeterFactory meterFactory, ITargetEventBus targetEv
public void Shutdown()
{
_disposables?.Dispose();
meterFactory.Create("godot-host-test")?.Dispose();
}
}