Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Hardening Activity usage for listener attached / not attached
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy D. Miller authored and Jeremy D. Miller committed Sep 12, 2022
1 parent d3998b3 commit ca01dd4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Jasper.Testing/Runtime/CommandBusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class CommandBusTests
[Fact]
public void use_current_activity_root_id_as_correlation_id_if_exists()
{
var activity = JasperTracing.StartExecution("foo", ObjectMother.Envelope());
activity.Start();
var activity = new Activity("process");
activity?.Start();

try
{
Expand All @@ -22,7 +22,7 @@ public void use_current_activity_root_id_as_correlation_id_if_exists()
}
finally
{
activity.Stop();
activity?.Stop();
}
}
}
3 changes: 2 additions & 1 deletion src/Jasper.Testing/Runtime/JasperTracingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public when_creating_an_execution_activity()
theEnvelope.CorrelationId = Guid.NewGuid().ToString();
theEnvelope.Destination = new Uri("tcp:https://localhost:6666");

theActivity = JasperTracing.StartExecution("process", theEnvelope);
theActivity = new Activity("process");
theEnvelope.WriteTags(theActivity);
}

[Fact]
Expand Down
14 changes: 14 additions & 0 deletions src/Jasper/Envelope.Internals.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Jasper.Runtime;
using Jasper.Serialization;
using Jasper.Transports;
using Jasper.Transports.Sending;
Expand Down Expand Up @@ -168,4 +170,16 @@ internal static Envelope ForPing(Uri destination)
Destination = destination
};
}

internal void WriteTags(Activity activity)
{
activity.MaybeSetTag(JasperTracing.MessagingSystem, Destination?.Scheme); // This needs to vary
activity.MaybeSetTag(JasperTracing.MessagingDestination, Destination);
activity.SetTag(JasperTracing.MessagingMessageId, Id);
activity.SetTag(JasperTracing.MessagingConversationId, CorrelationId);
activity.SetTag(JasperTracing.MessageType, MessageType); // Jasper specific
activity.MaybeSetTag(JasperTracing.PayloadSizeBytes, MessagePayloadSize);

activity.MaybeSetTag(JasperTracing.MessagingCausationId, CausationId);
}
}
6 changes: 3 additions & 3 deletions src/Jasper/Runtime/HandlerPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Task InvokeAsync(Envelope envelope, IChannelCallback channel)
return InvokeAsync(envelope, channel, activity);
}

public async Task InvokeAsync(Envelope envelope, IChannelCallback channel, Activity activity)
public async Task InvokeAsync(Envelope envelope, IChannelCallback channel, Activity? activity)
{
try
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public async Task InvokeAsync(Envelope envelope, IChannelCallback channel, Activ
}
finally
{
activity.Stop();
activity?.Stop();
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task InvokeNowAsync(Envelope envelope, CancellationToken cancellati
{
Logger.ExecutionFinished(envelope);
_contextPool.Return(context);
activity.Stop();
activity?.Stop();
}
}

Expand Down
15 changes: 5 additions & 10 deletions src/Jasper/Runtime/JasperTracing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@ internal static class JasperTracing



public static Activity StartExecution(string spanName, Envelope envelope,
public static Activity? StartExecution(string spanName, Envelope envelope,
ActivityKind kind = ActivityKind.Internal)
{
var activity = ActivitySource.StartActivity(spanName, kind) ?? new Activity(spanName);
activity.MaybeSetTag(MessagingSystem, envelope.Destination?.Scheme); // This needs to vary
activity.MaybeSetTag(MessagingDestination, envelope.Destination);
activity.SetTag(MessagingMessageId, envelope.Id);
activity.SetTag(MessagingConversationId, envelope.CorrelationId);
activity.SetTag(MessageType, envelope.MessageType); // Jasper specific
activity.MaybeSetTag(PayloadSizeBytes, envelope.MessagePayloadSize);

activity.MaybeSetTag(MessagingCausationId, envelope.CausationId);
var activity = ActivitySource.StartActivity(spanName, kind);
if (activity == null) return null;

envelope.WriteTags(activity);

return activity;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Jasper/Runtime/WorkerQueues/DurableReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public async ValueTask ReceivedAsync(IListener listener, Envelope envelope)
}
finally
{
activity.Stop();
activity?.Stop();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Jasper/Runtime/WorkerQueues/InlineReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async ValueTask ReceivedAsync(IListener listener, Envelope envelope)
}
finally
{
activity.Stop();
activity?.Stop();
}
}
}

0 comments on commit ca01dd4

Please sign in to comment.