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 -6
View File
@@ -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();
}
}