generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor MassTransit receive transaction (#19)
- Loading branch information
Showing
4 changed files
with
75 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 32 additions & 1 deletion
33
src/Elastic.Apm.Messaging.MassTransit/MassTransitExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Elastic.Apm.Api; | ||
using MassTransit; | ||
|
||
namespace Elastic.Apm.Messaging.MassTransit | ||
{ | ||
internal static class MassTransitExtensions | ||
{ | ||
private static readonly Dictionary<string, string> SchemeToSubType = new() | ||
{ | ||
{ "sb", "azureservicebus" } | ||
}; | ||
|
||
internal static void SetTracingData(this SendContext context, ISpan span) | ||
{ | ||
var tracingData = span.OutgoingDistributedTracingData.SerializeToString(); | ||
context.Headers.Set(Constants.TraceHeaderName, tracingData); | ||
context.Headers.Set( | ||
Constants.TraceHeaderName, | ||
tracingData); | ||
context.Headers.Set( | ||
Constants.MessageSourceHeaderName, | ||
context.DestinationAddress.AbsolutePath); | ||
} | ||
|
||
internal static DistributedTracingData? GetTracingData(this ReceiveContext context) | ||
{ | ||
var tracingData = context.TransportHeaders.Get<string>(Constants.TraceHeaderName); | ||
return DistributedTracingData.TryDeserializeFromString(tracingData); | ||
} | ||
|
||
internal static string GetMessageSource(this ReceiveContext context) | ||
{ | ||
return context.TransportHeaders.Get<string>(Constants.MessageSourceHeaderName); | ||
} | ||
|
||
internal static string GetSpanSubType(this SendContext context) | ||
{ | ||
var scheme = context.DestinationAddress.Scheme; | ||
|
||
return SchemeToSubType.TryGetValue(scheme, out var value) ? value : scheme; | ||
} | ||
|
||
internal static string GetDestinationAbsoluteName(this SendContext context) | ||
{ | ||
return context.DestinationAddress.AbsolutePath | ||
.AsSpan(1, context.DestinationAddress.AbsolutePath.Length - 1) | ||
.ToString(); | ||
} | ||
} | ||
} |