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

Add IServiceCollection extension methods to register ApmAgent #2326

Merged
merged 4 commits into from
Apr 8, 2024

Conversation

stevejgordon
Copy link
Contributor

@stevejgordon stevejgordon commented Apr 4, 2024

Fixes #2262

Newer releases of .NET have moved away from the older IHostBuilder and IApplicationBuilder mechanisms in Microsoft.Extensions.Hosting. To support registering the ApmAgent consistently in all templates which use the generic host from Microsoft.Extensions.Hosting, this PR adds support for registering the agent via the IServiceCollection. This mechanism is now favoured as it is consistent and expected to be a viable long-term choice.

This PR also refactors the original tests for the Extensions.Hosting and Extensions.Logging libraries. Because the ApmAgent is a singleton, test cases cannot make assertions in isolation. To work around this, the test cases now spin up a test app in a separate process. The test app accepts various args to configure its behaviour so that the key test conditions can be applied and validated.

Docs are updated to reflect the new extension methods.

@stevejgordon
Copy link
Contributor Author

The azure and profiler tests have been particularly flakey on this PR but nothing in it should have affected them so I think it's good to go!

@stevejgordon stevejgordon merged commit 1651da8 into main Apr 8, 2024
13 checks passed
@stevejgordon stevejgordon deleted the enhancement/2262 branch April 8, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration of .NET 7+ using HostApplicationBuilder
2 participants