Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test ElasticApmAgent_<Version>.zip on CI #1073

Closed
russcam opened this issue Dec 1, 2020 · 0 comments · Fixed by #1167
Closed

Test ElasticApmAgent_<Version>.zip on CI #1073

russcam opened this issue Dec 1, 2020 · 0 comments · Fixed by #1167
Assignees
Labels
agent-dotnet automated testing Issues related to automated testing automation ci

Comments

@russcam
Copy link
Contributor

russcam commented Dec 1, 2020

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

  1. A barebones sample ASP.NET Core application is introduced, as the target application for startup hood testing
  2. A build target is added to the scripts F# project with a dependency on the agent-zip target that
    1. unzips the ElasticApmAgent_.zip to a known location
    2. uses docker to run the sample ASP.NET Core with the DOTNET_STARTUP_HOOKS environment variable pointing to the unzipped ElasticApmAgent_ location
  3. 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.

@russcam russcam added automation automated testing Issues related to automated testing ci labels Dec 1, 2020
@russcam russcam self-assigned this Jan 29, 2021
russcam added a commit that referenced this issue Feb 11, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-dotnet automated testing Issues related to automated testing automation ci
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant