continuity/Continuity.AuthServer/Consumers/PacketConsumer.cs

36 lines
1.3 KiB
C#

// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
using Continuity.AuthServer.Packets;
using JetBrains.Annotations;
using MassTransit;
using OpenTelemetry.Trace;
using Rai.PacketMediator;
using Wonderking.Packets;
namespace Continuity.AuthServer.Consumers;
[UsedImplicitly]
public class PacketConsumer : IConsumer<RawPacket>
{
private readonly PacketDistributorService<OperationCode, AuthSession> _distributorService;
private readonly TracerProvider _tracerProvider;
public PacketConsumer(PacketDistributorService<OperationCode, AuthSession> distributorService, TracerProvider tracerProvider)
{
_distributorService = distributorService;
_tracerProvider = tracerProvider;
}
public Task Consume(ConsumeContext<RawPacket> context)
{
var tracer = _tracerProvider.GetTracer("Rai.PacketMediator");
using var scope = tracer.StartActiveSpan("PacketHandler");
scope.SetAttribute("PacketId", context.Message.OperationCode.ToString());
scope.SetAttribute("SessionId", context.Message.Session.Id.ToString());
scope.SetAttribute("PacketSize", context.Message.MessageBody.Length);
return _distributorService.AddPacketAsync(context.Message.MessageBody, context.Message.OperationCode, context.Message.Session);
}
}