-
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.
feat: Parse Azure Function HttpTrigger parameters (#2776)
- Loading branch information
1 parent
e545c43
commit 7e8c28b
Showing
16 changed files
with
747 additions
and
415 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
56 changes: 56 additions & 0 deletions
56
...gent/Extensions/Providers/Wrapper/AzureFunction/FunctionsHttpProxyingMiddlewareWrapper.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,56 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using NewRelic.Agent.Api; | ||
using NewRelic.Agent.Extensions.Providers.Wrapper; | ||
|
||
namespace NewRelic.Providers.Wrapper.AzureFunction; | ||
|
||
public class FunctionsHttpProxyingMiddlewareWrapper : IWrapper | ||
{ | ||
private const string WrapperName = "FunctionsHttpProxyingMiddlewareWrapper"; | ||
|
||
public bool IsTransactionRequired => false; | ||
|
||
public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo) | ||
{ | ||
return new CanWrapResponse(WrapperName.Equals(methodInfo.RequestedWrapperName)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets request method / path for Azure function HttpTrigger invocations | ||
/// in apps that use the Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore package | ||
/// </summary> | ||
public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction) | ||
{ | ||
if (agent.Configuration.AzureFunctionModeEnabled) | ||
{ | ||
dynamic httpContext; | ||
switch (instrumentedMethodCall.MethodCall.Method.MethodName) | ||
{ | ||
case "AddHttpContextToFunctionContext": | ||
httpContext = instrumentedMethodCall.MethodCall.MethodArguments[1]; | ||
|
||
agent.CurrentTransaction.SetRequestMethod(httpContext.Request.Method); | ||
agent.CurrentTransaction.SetUri(httpContext.Request.Path); | ||
break; | ||
case "TryHandleHttpResult": | ||
if (!agent.CurrentTransaction.HasHttpResponseStatusCode) // these handlers seem to get called more than once; only set the status code one time | ||
{ | ||
httpContext = instrumentedMethodCall.MethodCall.MethodArguments[2]; | ||
agent.CurrentTransaction.SetHttpResponseStatusCode(httpContext.Response.StatusCode); | ||
} | ||
break; | ||
case "TryHandleOutputBindingsHttpResult": | ||
if (!agent.CurrentTransaction.HasHttpResponseStatusCode) // these handlers seem to get called more than once; only set the status code one time | ||
{ | ||
httpContext = instrumentedMethodCall.MethodCall.MethodArguments[1]; | ||
agent.CurrentTransaction.SetHttpResponseStatusCode(httpContext.Response.StatusCode); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
return Delegates.NoOp; | ||
} | ||
} |
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
Oops, something went wrong.