-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC - razor page instrumentation. Needs work in transaction / segment…
… naming
- Loading branch information
1 parent
f1036f2
commit 8a50d96
Showing
3 changed files
with
72 additions
and
0 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
66 changes: 66 additions & 0 deletions
66
.../Extensions/Providers/Wrapper/AspNetCore6Plus/PageActionInvokeHandlerAsyncWrapper6Plus.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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.Controllers; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using NewRelic.Agent.Api; | ||
using NewRelic.Agent.Api.Experimental; | ||
using NewRelic.Agent.Extensions.Providers.Wrapper; | ||
using NewRelic.Reflection; | ||
|
||
namespace NewRelic.Providers.Wrapper.AspNetCore6Plus | ||
{ | ||
public class PageActionInvokeHandlerAsyncWrapper6Plus : IWrapper | ||
{ | ||
private static Func<object, PageContext> _getPageContext; | ||
|
||
static PageActionInvokeHandlerAsyncWrapper6Plus() | ||
{ | ||
_getPageContext = VisibilityBypasser.Instance.GenerateFieldReadAccessor<PageContext>("Microsoft.AspNetCore.Mvc.RazorPages", | ||
"Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker", "_pageContext"); | ||
} | ||
|
||
public bool IsTransactionRequired => true; | ||
|
||
public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo) | ||
{ | ||
return new CanWrapResponse("PageActionInvokeHandlerAsyncWrapper6Plus".Equals(methodInfo.RequestedWrapperName)); | ||
} | ||
|
||
public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction) | ||
{ | ||
if (instrumentedMethodCall.IsAsync) | ||
{ | ||
transaction.AttachToAsync(); | ||
} | ||
|
||
var pageContext = _getPageContext(instrumentedMethodCall.MethodCall.InvocationTarget); | ||
|
||
var actionDescriptor = pageContext.ActionDescriptor; | ||
|
||
var transactionName = CreateTransactionName(actionDescriptor); | ||
|
||
transaction.SetWebTransactionName(WebTransactionType.Action, transactionName, TransactionNamePriority.FrameworkHigh); | ||
|
||
var actionDescriptorPageTypeInfo = actionDescriptor.PageTypeInfo; | ||
var pageTypeName = actionDescriptorPageTypeInfo.Name; | ||
|
||
var segment = transaction.StartMethodSegment(instrumentedMethodCall.MethodCall, pageTypeName, "uhh_what_goes_here"); | ||
|
||
var segmentApi = segment.GetExperimentalApi(); | ||
segmentApi.UserCodeNamespace = actionDescriptorPageTypeInfo.FullName; | ||
segmentApi.UserCodeFunction = "uhh_what_goes_here"; | ||
|
||
return Delegates.GetAsyncDelegateFor<Task>(agent, segment, TaskContinueWithOption.None); | ||
} | ||
|
||
private static string CreateTransactionName(CompiledPageActionDescriptor actionDescriptor) | ||
{ | ||
var transactionName = $"Pages{actionDescriptor.DisplayName}"; | ||
|
||
return transactionName; | ||
} | ||
} | ||
} |