// 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 { private readonly PacketDistributorService _distributorService; private readonly TracerProvider _tracerProvider; public PacketConsumer(PacketDistributorService distributorService, TracerProvider tracerProvider) { _distributorService = distributorService; _tracerProvider = tracerProvider; } public Task Consume(ConsumeContext 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); } }