Skip to content

Commit

Permalink
Prevent inlining in integration test app methods (#636)
Browse files Browse the repository at this point in the history
* prevent inlining DT API integration test application

* Prevent inlining two more test app methods

* Prevent inlining of trace-decorated methods
  • Loading branch information
nr-ahemsath authored Jul 8, 2021
1 parent 7875961 commit de84c45
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public CustomMiddleware(RequestDelegate next)
}

[Trace]
[MethodImpl(MethodImplOptions.NoInlining)]
public async Task Invoke(HttpContext context)
{
await MiddlewareMethodAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public CustomMiddleware(RequestDelegate next)
}

[Trace]
[MethodImpl(MethodImplOptions.NoInlining)]
public async Task Invoke(HttpContext context)
{
await MiddlewareMethodAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -30,6 +31,7 @@ static void Main(string[] args)
/// for recording the response time at its end.
/// </summary>
[Transaction]
[MethodImpl(MethodImplOptions.NoInlining)]
private static void OuterInstrumentedMethod()
{
Thread.Sleep(TimeSpan.FromSeconds(_delaySeconds));
Expand All @@ -41,6 +43,7 @@ private static void OuterInstrumentedMethod()
/// the response time of the transaction because it was not the one that created the transaction.
/// </summary>
[Transaction]
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InnerInstrumentedMethod()
{
Thread.Sleep(TimeSpan.FromSeconds(_delaySeconds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using CommandLine;
using NewRelic.Api.Agent;
Expand Down Expand Up @@ -73,6 +74,7 @@ static void Main(string[] args)
}

[Transaction]
[MethodImpl(MethodImplOptions.NoInlining)]
private static IDistributedTracePayload CallCreateDTPayload()
{
var currentTransaction = _agent.CurrentTransaction;
Expand All @@ -83,6 +85,7 @@ private static IDistributedTracePayload CallCreateDTPayload()
}

[Transaction]
[MethodImpl(MethodImplOptions.NoInlining)]
private static void CallAcceptDTPayload(IDistributedTracePayload payload)
{
var currentTransaction = _agent.CurrentTransaction;
Expand All @@ -93,13 +96,15 @@ private static void CallAcceptDTPayload(IDistributedTracePayload payload)
}

[Transaction]
[MethodImpl(MethodImplOptions.NoInlining)]
private static void CallInsertDTHeaders()
{
var currentTransaction = _agent.CurrentTransaction;
currentTransaction.InsertDistributedTraceHeaders(_carrier, _setHeaders);
}

[Transaction]
[MethodImpl(MethodImplOptions.NoInlining)]
private static void CallAcceptDTHeaders()
{
var currentTransaction = _agent.CurrentTransaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public CustomMiddleware(OwinMiddleware next) : base(next)
}

[Trace]
[MethodImpl(MethodImplOptions.NoInlining)]
public override async Task Invoke(IOwinContext context)
{
await MiddlewareMethodAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public CustomMiddleware(OwinMiddleware next) : base(next)
}

[Trace]
[MethodImpl(MethodImplOptions.NoInlining)]
public override async Task Invoke(IOwinContext context)
{
await MiddlewareMethodAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public CustomMiddleware(OwinMiddleware next) : base(next)
}

[Trace]
[MethodImpl(MethodImplOptions.NoInlining)]
public override async Task Invoke(IOwinContext context)
{
await MiddlewareMethodAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void Test()
new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/AcceptPayload/Ignored/MajorVersion", callCount = 1 },
new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/AcceptPayload/Ignored/Null", callCount = 1 },
new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/AcceptPayload/ParseException", callCount = 1 },
// The methods for GenerateAcceptSuccessMetric and GenerateCreateSuccesMetric result in AcceptPayload/Success metrics so we should look for two.
new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/AcceptPayload/Success", callCount = 2 },
// The methods for GenerateAcceptSuccessMetric and GenerateCreateSuccessMetric result in AcceptPayload/Success metrics so we should look for two.
new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/AcceptPayload/Success", callCount = 2 },
new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/AcceptPayload/Ignored/UntrustedAccount", callCount = 1 },
new Assertions.ExpectedMetric { metricName = @"Supportability/DistributedTrace/CreatePayload/Success", callCount = 1 },
};
Expand Down

0 comments on commit de84c45

Please sign in to comment.