feat: adapt to enabled observability features.
This commit is contained in:
@@ -35,6 +35,7 @@ public partial class GameServiceSource : RootServiceSource
|
||||
{
|
||||
serviceCollection.AddObservability(builder => builder
|
||||
.AddGrpcExporter("http://localhost:4317")
|
||||
.AddMeterName());
|
||||
.AddMeterName()
|
||||
.EnableObservabilityFeature(ObservabilityFeatures.Logging));
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Game.Target;
|
||||
using GodotHostTest.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OwofGames.AetherBind;
|
||||
using OwofGames.GodotHost.Observability;
|
||||
using OwofGames.GodotLume;
|
||||
@@ -23,13 +24,18 @@ public partial class LevelServiceSource : ServiceSource
|
||||
}
|
||||
|
||||
[WithProvider]
|
||||
private void OnScopeCreated(IActivitySourceFactory activitySourceFactory,
|
||||
private void OnScopeCreated(ILogger<LevelServiceSource> logger,
|
||||
IOptional<IActivitySourceFactory> activitySourceFactoryWrapper,
|
||||
IValueSetter<ITargetCollector> targetCollector, IValueSetter<ITargetSpawner> targetSpawner)
|
||||
{
|
||||
// ReSharper disable once ExplicitCallerInfoArgument - the caller name is not significant in this case
|
||||
_levelActivity = activitySourceFactory.ActivitySource.StartActivity("Level") ??
|
||||
throw new InvalidOperationException(
|
||||
"No listeners for the activity - is OpenTelemetry running?");
|
||||
if (activitySourceFactoryWrapper.TryGet(out var activitySourceFactory))
|
||||
// ReSharper disable once ExplicitCallerInfoArgument - the caller name is not significant in this case
|
||||
_levelActivity = activitySourceFactory.ActivitySource.StartActivity("Level") ??
|
||||
throw new InvalidOperationException(
|
||||
"No listeners for the activity - is OpenTelemetry running?");
|
||||
else
|
||||
logger.LogWarning("Tracing not enabled, cannot start the activity.");
|
||||
|
||||
targetCollector.Set(_targetSpawner);
|
||||
targetSpawner.Set(_targetSpawner);
|
||||
}
|
||||
@@ -37,6 +43,6 @@ public partial class LevelServiceSource : ServiceSource
|
||||
public override void _Ready()
|
||||
{
|
||||
// after 3 seconds, dispose the activity for simulation purposes
|
||||
GetTree().CreateTimer(3).Timeout += _levelActivity!.Dispose;
|
||||
GetTree().CreateTimer(3).Timeout += () => _levelActivity?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user