Skip to content

Commit

Permalink
Reverting "unused" wrapper that was deleted. Apparently it's not as "…
Browse files Browse the repository at this point in the history
…unused" as it seems...
  • Loading branch information
tippmar-nr committed Oct 27, 2023
1 parent 2c284fb commit 0aba4d7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void Initialize(string installPathExtensionsDirectory)
{ "NewRelic.Providers.Wrapper.AspNetCore.InvokeActionMethodAsync", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.AspNetCore.dll") },

{ "GenericHostWebHostBuilderExtensionsWrapper6Plus", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.AspNetCore6Plus.dll") },
{ "BuildCommonServicesWrapper6Plus", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.AspNetCore6Plus.dll") },
{ "InvokeActionMethodAsyncWrapper6Plus", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.AspNetCore6Plus.dll") },
{ "ResponseCompressionBodyOnWriteWrapper", Path.Combine(_installPathExtensionsDirectory, "NewRelic.Providers.Wrapper.AspNetCore6Plus.dll") },

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using NewRelic.Agent.Api;
using NewRelic.Agent.Extensions.Providers.Wrapper;

namespace NewRelic.Providers.Wrapper.AspNetCore6Plus
{
public class BuildCommonServicesWrapper6Plus : IWrapper
{
public bool IsTransactionRequired => false;

public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
{
return new CanWrapResponse(nameof(BuildCommonServicesWrapper6Plus).Equals(methodInfo.RequestedWrapperName));
}

public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction)
{
//Do nothing at start of method

return Delegates.GetDelegateFor<IServiceCollection>(onSuccess: HandleSuccess);

void HandleSuccess(IServiceCollection services)
{
//Forced evaluation is important. Do not remove ToList()
var startupFilters = services.Where(serviceDescriptor => serviceDescriptor.ServiceType == typeof(IStartupFilter)).ToList();

services.AddTransient<IStartupFilter>(provider => new AddNewRelicStartupFilter(agent));

foreach (var filter in startupFilters)
{
services.Remove(filter); // Remove from early in pipeline
services.Add(filter); // Add to end after our AddNewRelicStartupFilter
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ SPDX-License-Identifier: Apache-2.0
<exactMethodMatcher methodName="ConfigureWebHost" />
</match>
</tracerFactory>
<tracerFactory name="BuildCommonServicesWrapper6Plus">
<match assemblyName="Microsoft.AspNetCore.Hosting" className="Microsoft.AspNetCore.Hosting.WebHostBuilder" minVersion="6.0.0.0">
<exactMethodMatcher methodName="BuildCommonServices" />
</match>
</tracerFactory>
<tracerFactory name="InvokeActionMethodAsyncWrapper6Plus">
<match assemblyName="Microsoft.AspNetCore.Mvc.Core" className="Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker" minVersion="6.0.0.0">
<exactMethodMatcher methodName="InvokeActionMethodAsync" />
Expand Down

0 comments on commit 0aba4d7

Please sign in to comment.