chore: otlp adjustments

This commit is contained in:
Timothy Schenk 2024-02-05 18:20:57 +01:00
parent efd261be77
commit 4982db6609
Signed by: rainote
SSH key fingerprint: SHA256:pnkNSDwpAnaip00xaZlVFHKKsS7T8UtOomMzvs0yITE
2 changed files with 11 additions and 12 deletions

View file

@ -1,9 +1,9 @@
// 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 Continuity.AuthServer.Packets; using Continuity.AuthServer.Packets;
using JetBrains.Annotations; using JetBrains.Annotations;
using MassTransit; using MassTransit;
using OpenTelemetry.Trace;
using Rai.PacketMediator; using Rai.PacketMediator;
using Wonderking.Packets; using Wonderking.Packets;
@ -14,23 +14,22 @@ public class PacketConsumer : IConsumer<RawPacket>
{ {
private readonly PacketDistributorService<OperationCode, AuthSession> _distributorService; private readonly PacketDistributorService<OperationCode, AuthSession> _distributorService;
private readonly TracerProvider _tracerProvider; private readonly ActivitySource _activitySource;
public PacketConsumer(PacketDistributorService<OperationCode, AuthSession> distributorService, TracerProvider tracerProvider) public PacketConsumer(PacketDistributorService<OperationCode, AuthSession> distributorService)
{ {
_distributorService = distributorService; _distributorService = distributorService;
_tracerProvider = tracerProvider; _activitySource = new ActivitySource(nameof(PacketConsumer));
} }
public Task Consume(ConsumeContext<RawPacket> context) public Task Consume(ConsumeContext<RawPacket> context)
{ {
var tracer = _tracerProvider.GetTracer("Rai.PacketMediator"); using var activity = _activitySource?.StartActivity("PacketConsumption");
activity?.SetTag("PacketId", context.Message.OperationCode.ToString());
activity?.SetTag("SessionId", context.Message.Session.Id.ToString());
activity?.SetTag("PacketSize", context.Message.MessageBody.Length);
using var scope = tracer.StartActiveSpan("PacketHandler"); return _distributorService.AddPacketAsync(context.Message.MessageBody, context.Message.OperationCode,
scope.SetAttribute("PacketId", context.Message.OperationCode.ToString()); context.Message.Session);
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);
} }
} }

View file

@ -53,7 +53,7 @@ if (configuration.GetValue<bool>("Tracing:Enabled"))
.WithTracing(tracing => .WithTracing(tracing =>
{ {
tracing.AddSource(nameof(Server)); tracing.AddSource(nameof(Server));
//tracing.AddSource("MassTransit"); tracing.AddSource("MassTransit");
tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true); tracing.AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true);
tracing.AddNpgsql(); tracing.AddNpgsql();
}) })