Skip to content

Commit

Permalink
Limit MassTransit v7 support to 7.1.0 and higher (#2024)
Browse files Browse the repository at this point in the history
* Updated 7x instrumentation with version ranges

Not quite working, integration tests are failing for StartBus with v7.0.0 due to transaction scope oddness

* Tweak names

* Better ConsoleMF logging

Added millisecond-level timestamps and thread id

* Only support 7.1.0 -> 7.3.1

* Actually make Tid a property

* Enable MassTransit integration tests

* Fix bug with transaction leakage

* Also detach from primary in 8.x filter

* Update project dependencies
  • Loading branch information
nr-ahemsath authored Nov 2, 2023
1 parent 760f41c commit c645b4c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/all_solutions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ jobs:
Logging.MaxSamplesStored,
Logging.MetricsAndForwarding,
Logging.ZeroMaxSamplesStored,
Owin,
Owin,
MassTransit,
ReJit.NetCore,
ReJit.NetFramework,
RequestHandling,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
namespaces="[ 'AgentFeatures', 'AgentLogs', 'AgentMetrics', 'Api', 'AppDomainCaching', 'AspNetCore', 'BasicInstrumentation', 'CatInbound', 'CatOutbound', 'CodeLevelMetrics', 'Configuration', \
'CSP', 'CustomAttributes', 'CustomInstrumentation', 'DataTransmission', 'DistributedTracing', 'Errors', 'HttpClientInstrumentation', 'InfiniteTracing', 'Logging.ContextData', \
'Logging.HsmAndCsp', 'Logging.LocalDecoration', 'Logging.LogLevelDetection', 'Logging.MaxSamplesStored', 'Logging.MetricsAndForwarding', 'Logging.ZeroMaxSamplesStored', \
'Owin', 'ReJit.NetCore', 'ReJit.NetFramework', 'RequestHandling', 'RequestHeadersCapture.AspNet', 'RequestHeadersCapture.AspNetCore', 'RequestHeadersCapture.EnvironmentVariables', \
'Owin', 'MassTransit', 'ReJit.NetCore', 'ReJit.NetFramework', 'RequestHandling', 'RequestHeadersCapture.AspNet', 'RequestHeadersCapture.AspNetCore', 'RequestHeadersCapture.EnvironmentVariables', \
'RequestHeadersCapture.Owin', 'RequestHeadersCapture.WCF', 'RestSharp', 'WCF.Client.IIS.ASPDisabled', 'WCF.Client.IIS.ASPEnabled', 'WCF.Client.Self', \
'WCF.Service.IIS.ASPDisabled', 'WCF.Service.IIS.ASPEnabled', 'WCF.Service.Self' ]"
else
Expand Down
61 changes: 35 additions & 26 deletions FullAgent.sln
Original file line number Diff line number Diff line change
Expand Up @@ -159,39 +159,48 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_docs", "_docs", "{5CEC5106
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Home", "src\Agent\NewRelic\Home\Home.csproj", "{5CF47B2E-9370-4FD8-B9BD-0D95D3EA167C}"
ProjectSection(ProjectDependencies) = postProject
{B65A0C00-100D-4F27-BAC7-6B8A9FC7619D} = {B65A0C00-100D-4F27-BAC7-6B8A9FC7619D}
{7C0C1700-6001-48F5-A214-6D392F225A07} = {7C0C1700-6001-48F5-A214-6D392F225A07}
{EA98ED03-D1B4-4283-8412-98985B06AFDA} = {EA98ED03-D1B4-4283-8412-98985B06AFDA}
{5BBEEC11-B753-4631-BCDD-43BE73B5CCAC} = {5BBEEC11-B753-4631-BCDD-43BE73B5CCAC}
{87EF7419-8390-49F2-8C51-4DF9B886E834} = {87EF7419-8390-49F2-8C51-4DF9B886E834}
{1593CA23-F7EC-42F2-A915-F5D5B18F8C6B} = {1593CA23-F7EC-42F2-A915-F5D5B18F8C6B}
{0962EF35-B457-479E-9A7A-EC43F9EC7180} = {0962EF35-B457-479E-9A7A-EC43F9EC7180}
{F889CE37-934F-48F2-A105-6C19CE292D37} = {F889CE37-934F-48F2-A105-6C19CE292D37}
{AA683341-1FF5-4D45-A831-1BAF3C100A5C} = {AA683341-1FF5-4D45-A831-1BAF3C100A5C}
{FA3ABF45-6DAB-47DC-B886-06BBEFE4292F} = {FA3ABF45-6DAB-47DC-B886-06BBEFE4292F}
{00B0CD4C-D7DE-4243-8185-79A912E48291} = {00B0CD4C-D7DE-4243-8185-79A912E48291}
{EFFD9051-E3AC-4266-9AF6-7ECC74C032BD} = {EFFD9051-E3AC-4266-9AF6-7ECC74C032BD}
{686AE051-BC8C-4AEC-803D-237AEB807CA9} = {686AE051-BC8C-4AEC-803D-237AEB807CA9}
{2FB30555-65A4-43D7-82AA-56BF203D3A96} = {2FB30555-65A4-43D7-82AA-56BF203D3A96}
{0962EF35-B457-479E-9A7A-EC43F9EC7180} = {0962EF35-B457-479E-9A7A-EC43F9EC7180}
{0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2} = {0C3E92D7-F16C-4575-9CBB-EB7349A4C5E2}
{0DC126D1-E782-4A41-BA3E-393083F08627} = {0DC126D1-E782-4A41-BA3E-393083F08627}
{10B2665A-B898-49F7-8BCA-2511872B0902} = {10B2665A-B898-49F7-8BCA-2511872B0902}
{1593CA23-F7EC-42F2-A915-F5D5B18F8C6B} = {1593CA23-F7EC-42F2-A915-F5D5B18F8C6B}
{203A8EA4-A0F2-4139-B02E-9B0F2B39C107} = {203A8EA4-A0F2-4139-B02E-9B0F2B39C107}
{22274460-3222-4474-B679-19E1F27A2CC3} = {22274460-3222-4474-B679-19E1F27A2CC3}
{9E9E1367-E09E-45F9-9A01-7D4489FBCB23} = {9E9E1367-E09E-45F9-9A01-7D4489FBCB23}
{C60C1767-A73A-4A9E-BAF1-D3463C7CEFEC} = {C60C1767-A73A-4A9E-BAF1-D3463C7CEFEC}
{64C7F267-5185-4AB7-9EB5-0183D8BB0171} = {64C7F267-5185-4AB7-9EB5-0183D8BB0171}
{230CDE78-9D21-4D10-9C4B-E00C88B8B021} = {230CDE78-9D21-4D10-9C4B-E00C88B8B021}
{279F8AD0-C959-476F-BD58-3581D9A33238} = {279F8AD0-C959-476F-BD58-3581D9A33238}
{2E6CF650-CB50-453D-830A-D00F0540FC2C} = {2E6CF650-CB50-453D-830A-D00F0540FC2C}
{2FB30555-65A4-43D7-82AA-56BF203D3A96} = {2FB30555-65A4-43D7-82AA-56BF203D3A96}
{3D69B4C9-FD16-461F-95AF-6FCA6EAA914E} = {3D69B4C9-FD16-461F-95AF-6FCA6EAA914E}
{44434B8F-EE14-49B0-855D-6EA0B48048BF} = {44434B8F-EE14-49B0-855D-6EA0B48048BF}
{D6E22195-EE69-4320-B08B-E68229FB69AB} = {D6E22195-EE69-4320-B08B-E68229FB69AB}
{84D9ED9A-2022-4C9B-BDED-DD9933A19CE5} = {84D9ED9A-2022-4C9B-BDED-DD9933A19CE5}
{203A8EA4-A0F2-4139-B02E-9B0F2B39C107} = {203A8EA4-A0F2-4139-B02E-9B0F2B39C107}
{4F5D77F3-B41A-44A7-AF10-2D5462CE0162} = {4F5D77F3-B41A-44A7-AF10-2D5462CE0162}
{570429FD-C785-4673-82DF-643D06B6DC53} = {570429FD-C785-4673-82DF-643D06B6DC53}
{5BBEEC11-B753-4631-BCDD-43BE73B5CCAC} = {5BBEEC11-B753-4631-BCDD-43BE73B5CCAC}
{614988AD-7C73-4E71-8F95-520D5F485984} = {614988AD-7C73-4E71-8F95-520D5F485984}
{C51E44B7-ADC9-4EDA-AAAE-F6307180A3EB} = {C51E44B7-ADC9-4EDA-AAAE-F6307180A3EB}
{64C7F267-5185-4AB7-9EB5-0183D8BB0171} = {64C7F267-5185-4AB7-9EB5-0183D8BB0171}
{686AE051-BC8C-4AEC-803D-237AEB807CA9} = {686AE051-BC8C-4AEC-803D-237AEB807CA9}
{6FA157C2-C50C-49E4-8CD7-50F2AD77A33D} = {6FA157C2-C50C-49E4-8CD7-50F2AD77A33D}
{279F8AD0-C959-476F-BD58-3581D9A33238} = {279F8AD0-C959-476F-BD58-3581D9A33238}
{710C7C7A-CD27-4F94-B2D3-9804BD848D57} = {710C7C7A-CD27-4F94-B2D3-9804BD848D57}
{7C0C1700-6001-48F5-A214-6D392F225A07} = {7C0C1700-6001-48F5-A214-6D392F225A07}
{84D9ED9A-2022-4C9B-BDED-DD9933A19CE5} = {84D9ED9A-2022-4C9B-BDED-DD9933A19CE5}
{87EF7419-8390-49F2-8C51-4DF9B886E834} = {87EF7419-8390-49F2-8C51-4DF9B886E834}
{8D2B52DD-D45C-481D-92F0-28990F168820} = {8D2B52DD-D45C-481D-92F0-28990F168820}
{A4B357E3-9CEF-492C-A0E2-2397D15F1CD6} = {A4B357E3-9CEF-492C-A0E2-2397D15F1CD6}
{9784EAEA-C32F-4DC4-BD84-4075BBA541AB} = {9784EAEA-C32F-4DC4-BD84-4075BBA541AB}
{4F5D77F3-B41A-44A7-AF10-2D5462CE0162} = {4F5D77F3-B41A-44A7-AF10-2D5462CE0162}
{570429FD-C785-4673-82DF-643D06B6DC53} = {570429FD-C785-4673-82DF-643D06B6DC53}
{9E9E1367-E09E-45F9-9A01-7D4489FBCB23} = {9E9E1367-E09E-45F9-9A01-7D4489FBCB23}
{A4B357E3-9CEF-492C-A0E2-2397D15F1CD6} = {A4B357E3-9CEF-492C-A0E2-2397D15F1CD6}
{AA683341-1FF5-4D45-A831-1BAF3C100A5C} = {AA683341-1FF5-4D45-A831-1BAF3C100A5C}
{B65A0C00-100D-4F27-BAC7-6B8A9FC7619D} = {B65A0C00-100D-4F27-BAC7-6B8A9FC7619D}
{C51E44B7-ADC9-4EDA-AAAE-F6307180A3EB} = {C51E44B7-ADC9-4EDA-AAAE-F6307180A3EB}
{C60C1767-A73A-4A9E-BAF1-D3463C7CEFEC} = {C60C1767-A73A-4A9E-BAF1-D3463C7CEFEC}
{D6E22195-EE69-4320-B08B-E68229FB69AB} = {D6E22195-EE69-4320-B08B-E68229FB69AB}
{D9428449-3E4B-4723-A8AA-1191315C7AAD} = {D9428449-3E4B-4723-A8AA-1191315C7AAD}
{E10BF2F9-D5CA-4330-8169-ED30D861697E} = {E10BF2F9-D5CA-4330-8169-ED30D861697E}
{EA98ED03-D1B4-4283-8412-98985B06AFDA} = {EA98ED03-D1B4-4283-8412-98985B06AFDA}
{EC34F023-223D-432F-9401-9C3ED1B75DE4} = {EC34F023-223D-432F-9401-9C3ED1B75DE4}
{EFFD9051-E3AC-4266-9AF6-7ECC74C032BD} = {EFFD9051-E3AC-4266-9AF6-7ECC74C032BD}
{F889CE37-934F-48F2-A105-6C19CE292D37} = {F889CE37-934F-48F2-A105-6C19CE292D37}
{F921A316-A8D2-4992-B894-69A3B5CA34E3} = {F921A316-A8D2-4992-B894-69A3B5CA34E3}
{FA3ABF45-6DAB-47DC-B886-06BBEFE4292F} = {FA3ABF45-6DAB-47DC-B886-06BBEFE4292F}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CosmosDb", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\CosmosDb\CosmosDb.csproj", "{E10BF2F9-D5CA-4330-8169-ED30D861697E}"
Expand All @@ -210,7 +219,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch", "src\Agent\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MassTransit", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\MassTransit\MassTransit.csproj", "{0DC126D1-E782-4A41-BA3E-393083F08627}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MassTransitLegacy", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\MassTransitLegacy\MassTransitLegacy.csproj", "{F921A316-A8D2-4992-B894-69A3B5CA34E3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MassTransitLegacy", "src\Agent\NewRelic\Agent\Extensions\Providers\Wrapper\MassTransitLegacy\MassTransitLegacy.csproj", "{F921A316-A8D2-4992-B894-69A3B5CA34E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -523,8 +532,8 @@ Global
{F921A316-A8D2-4992-B894-69A3B5CA34E3} = {5E86E10A-C38F-48CB-ADE9-67B22BB2F50A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35
SolutionGuid = {D8B98070-6B8E-403C-A07F-A3F2E4A3A3D0}
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = FullAgent.vsmdi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public async Task Send(ConsumeContext context, IPipe<ConsumeContext> next)
destination: destName);

transaction.AttachToAsync();
transaction.DetachFromPrimary();

transaction.AcceptDistributedTraceHeaders(context.Headers, GetHeaderValue, TransportType.AMQP);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ SPDX-License-Identifier: Apache-2.0

<tracerFactory name="TransportConfigLegacyWrapper">

<!--This classname works for MassTransit v7.0.0-->
<match assemblyName="MassTransit" className="MassTransit.Registration.TransportRegistrationBusFactory" maxVersion="8.0.0">
<match assemblyName="MassTransit" className="MassTransit.Registration.TransportRegistrationBusFactory`1" minVersion="7.1.0" maxVersion="8.0.0">
<exactMethodMatcher methodName="CreateBus" />
</match>
<!--This classname works for MassTransit v7.3.1-->
<match assemblyName="MassTransit" className="MassTransit.Registration.TransportRegistrationBusFactory`1" maxVersion="8.0.0">
<exactMethodMatcher methodName="CreateBus" />
</match>

<match assemblyName="MassTransit" className="MassTransit.BusFactoryExtensions" maxVersion="8.0.0">
<match assemblyName="MassTransit" className="MassTransit.BusFactoryExtensions" minVersion="7.1.0" maxVersion="8.0.0">
<exactMethodMatcher methodName="Build" parameters="MassTransit.IBusFactory,MassTransit.Configuration.IBusConfiguration,System.Collections.Generic.IEnumerable`1[GreenPipes.ValidationResult]" />
</match>
</tracerFactory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public async Task Send(ConsumeContext context, IPipe<ConsumeContext> next)
destination: destName);

transaction.AttachToAsync();
transaction.DetachFromPrimary();

transaction.AcceptDistributedTraceHeaders(context.Headers, GetHeaderValue, TransportType.AMQP);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace MultiFunctionApplicationHelpers
public static class ConsoleMFLogger
{

private static string LogTs => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss,fff");

private static int Tid => System.Threading.Thread.CurrentThread.ManagedThreadId;

public static void Info()
{
Info("");
Expand All @@ -18,7 +22,7 @@ public static void Info(params string[] message)
{
foreach (var msg in message)
{
Console.WriteLine($"{DateTime.Now.ToLongTimeString()} :{msg}");
Console.WriteLine($"{LogTs} tid:{Tid} {msg}");
}
}

Expand All @@ -31,13 +35,14 @@ public static void Error(params string[] message)
{
foreach (var msg in message)
{
Console.Error.WriteLine($"{DateTime.Now.ToLongTimeString()} :{msg}");
Console.Error.WriteLine($"{LogTs} tid:{Tid} {msg}");
}
}

public static void Error(Exception ex)
{
Error(ex.ToString());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,21 @@

<!--MassTransit-->
<ItemGroup>
<PackageReference Include="MassTransit" Version="7.3.1" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="MassTransit" Version="7.3.1" Condition="'$(TargetFramework)' == 'net471'" />

<PackageReference Include="MassTransit" Version="7.1.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="MassTransit" Version="7.1.0" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="MassTransit" Version="7.3.1" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="MassTransit" Version="8.1.1" Condition="'$(TargetFramework)' == 'net481'" />
<PackageReference Include="MassTransit" Version="7.3.1" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="MassTransit" Version="8.1.1" Condition="'$(TargetFramework)' == 'net7.0'" />

<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.1.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.1.0" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" Condition="'$(TargetFramework)' == 'net6.0'" />

<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.3.1" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.3.1" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.1.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.1.0" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.3.1" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.3.1" Condition="'$(TargetFramework)' == 'net6.0'" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public async Task StopBus()
[LibraryMethod]
[Transaction]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
public async Task Publish(string message)
public async Task Publish(string text)
{
var order = new Message() { Text = message };
await _bus.Publish(order);
ConsoleMFLogger.Info($"Published message {message}");
var message = new Message() { Text = text };
await _bus.Publish(message);
ConsoleMFLogger.Info($"Published message {text}");

// This sleep ensures that this transaction method is the one sampled for transaction trace data
Thread.Sleep(1000);
Expand Down

0 comments on commit c645b4c

Please sign in to comment.