From aa09d0b755a9f25e14b3a391c114695f2633667b Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Fri, 24 Nov 2023 18:29:57 +0100 Subject: [PATCH] chore: tracing for generic PacketHandler --- Server/PacketHandlers/IPacketHandler.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Server/PacketHandlers/IPacketHandler.cs b/Server/PacketHandlers/IPacketHandler.cs index f1d8ef6..71942ca 100644 --- a/Server/PacketHandlers/IPacketHandler.cs +++ b/Server/PacketHandlers/IPacketHandler.cs @@ -1,5 +1,6 @@ // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. +using System.Diagnostics; using JetBrains.Annotations; using NetCoreServer; using Wonderking.Packets; @@ -14,13 +15,18 @@ public interface IPacketHandler : IPacketHandler where T : IPacket async Task 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 true; + return false; } - return false; + activity.SetTag("packetName", packet.ToString()); + activity.SetTag("handlerName", this.ToString()); + await HandleAsync(tPacket, session); + + return true; } }