Skip to content

Commit

Permalink
Fix masstransit send as root transaction #25
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci authored Jan 21, 2022
1 parent 20aa527 commit a1eeff7
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ public void OnNext(KeyValuePair<string, object?> value)
HandleSendStart(activity, value.Value);
return;
case Constants.Events.SendStop:
HandleStop(activity.SpanId, activity.Duration);
HandleStop(activity.SpanId);
return;
case Constants.Events.ReceiveStart:
HandleReceiveStart(activity, value.Value);
return;
case Constants.Events.ReceiveStop:
HandleStop(activity.ParentSpanId, activity.Parent!.Duration);
HandleStop(activity.ParentSpanId);
return;
case Constants.Events.ConsumeStart:
HandleConsumeStart(activity, value.Value);
return;
case Constants.Events.ConsumeStop:
HandleStop(activity.SpanId, activity.Duration);
HandleStop(activity.SpanId);
return;
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ private void HandleSendStart(Activity activity, object? context)
Uri? address = isSendingResponse ? sendContext.SourceAddress : sendContext.DestinationAddress;
span.Context.Destination = new Destination
{
Address = sendContext.DestinationAddress.AbsoluteUri,
Address = sendContext.DestinationAddress.AbsoluteUri,
Service = new Destination.DestinationService
{
Resource = $"{subType}{address.AbsolutePath}"
Expand All @@ -117,7 +117,7 @@ private void HandleSendStart(Activity activity, object? context)
}
else
{
_multipleActivities.TryAdd(activity.SpanId, new[] { span, executionSegment });
_multipleActivities.TryAdd(ActivitySpanId.CreateFromString(executionSegment.Id.AsSpan()), new[] { span, executionSegment });
}
}
}
Expand Down Expand Up @@ -235,16 +235,15 @@ private void HandleConsumeStart(Activity activity, object? context)
}
}

private void HandleStop(ActivitySpanId? spanId, TimeSpan duration)
private void HandleStop(ActivitySpanId? spanId)
{
if (spanId.HasValue)
{
if (_activities.Any() &&
_activities.TryRemove(spanId.Value, out IExecutionSegment? executionSegment) &&
executionSegment != null)
{
executionSegment.Duration = duration.TotalMilliseconds;
executionSegment.End();
executionSegment.End();
}

if (_multipleActivities.Any() &&
Expand All @@ -253,7 +252,6 @@ private void HandleStop(ActivitySpanId? spanId, TimeSpan duration)
{
for (var i = 0; i < executionSegments.Length; i++)
{
executionSegments[i].Duration = duration.TotalMilliseconds;
executionSegments[i].End();
}
}
Expand Down

0 comments on commit a1eeff7

Please sign in to comment.