You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once the ElasticApmAgent_.zip build is running on CI (#1072), the zip file should be tested to ensure that the generated artifact can auto instrument an ASP.NET Core web application without code changes.
Possible implementation
A barebones sample ASP.NET Core application is introduced, as the target application for startup hood testing
A build target is added to the scripts F# project with a dependency on the agent-zip target that
unzips the ElasticApmAgent_.zip to a known location
uses docker to run the sample ASP.NET Core with the DOTNET_STARTUP_HOOKS environment variable pointing to the unzipped ElasticApmAgent_ location
Collects agent logs from the sample application, or indexed data from Elasticsearch to verify that auto instrumentation is operating correctly.
Investigation
From current investigation, the major version of System.Diagnostics.DiagnosticSource that the agent references must match the version that the web application uses.
The agent subscribes to diagnostic events using DiagnosticListener.AllListeners.Subscribe(...). If the ASP.NET Core application is using System.Diagnostics.DiagnosticSource 4.x, but the APM agent is using System.Diagnostics.DiagnosticSource 5.0.0, the agent will not be able to load the 5.0.0 version of the assembly into AssemblyLoadContext.Default - a FileLoadException is thrown.
An approach to load assemblies with conflicting versions is to create a different AssembyLoadContext and load them into this context. Using a different AssemblyLoadContext to load a 5.0.0 version and a 4.x version of System.Diagnostics.DiagnosticSource works in getting around the version conflict, but since the agent depends on the 5.0.0 version, it will try to subscribe to the DiagnosticListener.AllListeners property of the 5.0.0 version, not the 4.x version that the application is publishing events to. Further, the static DiagnosticListener.AllListeners property is isolated to the context in which it is loaded, so the agent assemblies that subscribe need to be loaded into the same context and be binary compatible, which doesn't seem to be the case if they're compiled against a different version. One way to get around this issue is to reference System.Diagnostics.DiagnosticSource 5.0.0 as a dependency of the application, which works, but we might want to take an alternative approach that doesn't potentially require a user to make changes to their application.
The text was updated successfully, but these errors were encountered:
This commit tests that the APM agent startup hook feature is able to
configure and setup the agent for ASP.NET Core 3.0, 3.1 and
ASP.NET 5, and send APM data to APM server.
A sample ASP.NET (Core) application is included as a target application
for startup hooks. Tests start the application, along with a test
APM server, make a request to the application, and assert that
APM data is captured by APM server.
A DotnetProject type is introduced that executes commands with
dotnet executable to create, publish and run dotnet projects. This is
used to test startup hooks for webapi, webapp and mvc projects for
netcoreapp3.0, netcoreapp3.1 and net5.0 frameworks.
Startup hook tests run as part of the Tests stage on Linux.
A separate Startup Hooks stage is introduced on Windows for testing.
Other changes:
- Loosen agent version assertion in Test APM server
The Test APM server may be run with an agent version built from a different commit
than the current one, so loosen the agent version assertion to just check for
major.minor.patch _without_ the commit suffix.
- Add OnReceive event to Test APM server
Allows blocking a thread until APM server receives data, which is useful for testing.
- Don't invoke MSBuild on CI in build project automation
Not needed for the current setup. F# Make (FAKE) appears to be invoking MSBuild.exe
that does not have access to .NET Core SDKs, which requires further investigation.
- Add dotnet 3.0 SDK to CI tests
Added to build and test startup hooks for netcoreapp3.0
Closes#1073
Relates: #1051, #1072
Once the ElasticApmAgent_.zip build is running on CI (#1072), the zip file should be tested to ensure that the generated artifact can auto instrument an ASP.NET Core web application without code changes.
Possible implementation
agent-zip
target thatDOTNET_STARTUP_HOOKS
environment variable pointing to the unzipped ElasticApmAgent_ locationInvestigation
From current investigation, the major version of
System.Diagnostics.DiagnosticSource
that the agent references must match the version that the web application uses.The agent subscribes to diagnostic events using
DiagnosticListener.AllListeners.Subscribe(...)
. If the ASP.NET Core application is usingSystem.Diagnostics.DiagnosticSource
4.x, but the APM agent is usingSystem.Diagnostics.DiagnosticSource
5.0.0, the agent will not be able to load the 5.0.0 version of the assembly intoAssemblyLoadContext.Default
- aFileLoadException
is thrown.An approach to load assemblies with conflicting versions is to create a different
AssembyLoadContext
and load them into this context. Using a differentAssemblyLoadContext
to load a 5.0.0 version and a 4.x version ofSystem.Diagnostics.DiagnosticSource
works in getting around the version conflict, but since the agent depends on the 5.0.0 version, it will try to subscribe to theDiagnosticListener.AllListeners
property of the 5.0.0 version, not the 4.x version that the application is publishing events to. Further, the staticDiagnosticListener.AllListeners
property is isolated to the context in which it is loaded, so the agent assemblies that subscribe need to be loaded into the same context and be binary compatible, which doesn't seem to be the case if they're compiled against a different version. One way to get around this issue is to referenceSystem.Diagnostics.DiagnosticSource
5.0.0 as a dependency of the application, which works, but we might want to take an alternative approach that doesn't potentially require a user to make changes to their application.The text was updated successfully, but these errors were encountered: