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
+2 -1
View File
@@ -35,6 +35,7 @@ public partial class GameServiceSource : RootServiceSource
{
serviceCollection.AddObservability(builder => builder
.AddGrpcExporter("http://localhost:4317")
.AddMeterName());
.AddMeterName()
.EnableObservabilityFeature(ObservabilityFeatures.Logging));
}
}
+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();
}
}
+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();
}
}
+1
View File
@@ -14,6 +14,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABatchExportProcessor_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fc8dd41e266838cc76bfa11d9dfab1ac2b969fe1ca445be5736143f97e378c_003FBatchExportProcessor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F71c28e8d0d254cb69b7b78690e099f6183800_003Fa8_003F2e82b19d_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGodotHostTest_002EGame_002ELevel_002ELevelServiceSource_002EOnScopeCreated_002EWithProvider_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003F7e88428147db393265e1cfcb5461548dc57aaf3_003FGodotHostTest_002EGame_002ELevel_002ELevelServiceSource_002EOnScopeCreated_002EWithProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGodotHostTest_002EGame_002ELevel_002ELevelServiceSource_002EOnScopeCreated_002EWithProvider_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ff1f7397c8131df63b08679a746605d20167b3792_003FGodotHostTest_002EGame_002ELevel_002ELevelServiceSource_002EOnScopeCreated_002EWithProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGodotHostTest_002EGame_002ELevel_002ELevelServiceSource_002EOnScopeCreated_002EWithProvider_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ff67e9a43d7ceeaa29fd4ff907a3ed16718c33f2_003FGodotHostTest_002EGame_002ELevel_002ELevelServiceSource_002EOnScopeCreated_002EWithProvider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGodotObject_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003F4b3cf0d6385fc1f8b61f68a3e1df5132e355f1c63b49372b4c670e76f3_003FGodotObject_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHttpClient_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F817267d4eb7342ab80e0efd5613f1765199200_003F52_003F81ac2983_003FHttpClient_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>