chore: tracing for generic PacketHandler
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 1s
Build, Package and Push Images / build (push) Successful in 30s
Build, Package and Push Images / sbom-scan (push) Successful in 34s
Build, Package and Push Images / sonarqube (push) Successful in 1m25s
Build, Package and Push Images / container-build (push) Successful in 1m29s
Build, Package and Push Images / container-sbom-scan (push) Successful in 34s

This commit is contained in:
Timothy Schenk 2023-11-24 18:29:57 +01:00
parent 0704d9f07d
commit aa09d0b755

View file

@ -1,5 +1,6 @@
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
using System.Diagnostics;
using JetBrains.Annotations; using JetBrains.Annotations;
using NetCoreServer; using NetCoreServer;
using Wonderking.Packets; using Wonderking.Packets;
@ -14,13 +15,18 @@ public interface IPacketHandler<in T> : IPacketHandler where T : IPacket
async Task<bool> IPacketHandler.TryHandleAsync(IPacket packet, TcpSession session) async Task<bool> IPacketHandler.TryHandleAsync(IPacket packet, TcpSession session)
{ {
if (packet is T tPacket) var activitySource = new ActivitySource(nameof(Server));
using var activity = activitySource.StartActivity("PacketHandlerHandleAsync");
if (packet is not T tPacket)
{ {
await HandleAsync(tPacket, session); return false;
return true;
} }
return false; activity.SetTag("packetName", packet.ToString());
activity.SetTag("handlerName", this.ToString());
await HandleAsync(tPacket, session);
return true;
} }
} }