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

ILogger integration fix for net6 when WebApplicationBuilder is used #3003

Merged
merged 15 commits into from
Oct 18, 2023

Conversation

lachmatt
Copy link
Contributor

@lachmatt lachmatt commented Oct 12, 2023

Why

Fixes #2994

What

Logs are exported multiple times for ASP.NET Core apps targeting net6 when WebApplicationBuilder is used.
In such scenario, integration is called on 2 related service collections: WebApplicationServiceCollection and ServiceCollection.
Integration tries to detect if it was called before on given IServiceCollection instance, but it doesn't work in this case, as it is called on ServiceCollection instance before services are copied to it from WebApplicationServiceCollection instance (on which integration was called before). This results in same logs being exported 4 times (duplicated loggers with duplicated processors).

Before #2975, integration was not being called if builder.Services was not of ServiceCollection type. That caused an issue when HostingStartupAssembly was configured to enable the integration (and bytecode instrumentation was disabled) for apps targeting net6 when WebApplicationBuilder was used.

The fix checks if HostingStartupAssembly is configured, and doesn't run integration for net6 when WebApplicationBuilder is used on host's ServiceCollection instance (OpenTelemetryLogger related services will be copied from WebApplicationServiceCollection instance, for which integration was called from HostingStartupAssembly).

All of the problematic scenarios (one that didn't work before #2975 and two that are being fixed with the PR) are covered by tests added in this PR.

Note:
As tests are waiting fixed amount of time to verify logs were not exported multiple times, this adds some time to the CI.

@rajkumar-rangaraj PTAL

Tests

Included in PR.

Checklist

  • CHANGELOG.md is updated.
    - [ ] Documentation is updated.
  • New features are covered by tests.

@lachmatt lachmatt requested a review from a team October 12, 2023 11:50
@lachmatt
Copy link
Contributor Author

lachmatt commented Oct 12, 2023

Looking into CI failure for macos (TestHost process is crashing)

@lachmatt lachmatt marked this pull request as draft October 12, 2023 14:26
Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick pass, it lgtm at this time, will do a more detailed pass when it is not draft anymore.

CHANGELOG.md Outdated Show resolved Hide resolved
@lachmatt
Copy link
Contributor Author

Looking into CI failure for macos (TestHost process is crashing)

I ran smoke test when bytecode instrumentation was not enabled, and it still crashed. It seems to be connected to addition of new kind of test app, I think this could be fixed as a part of separate issue. For now, I skipped problematic scenario.

@lachmatt lachmatt marked this pull request as ready for review October 13, 2023 16:26
Copy link
Contributor

@rajkumar-rangaraj rajkumar-rangaraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've left a few minor comments to address.

@Kielek Kielek enabled auto-merge (squash) October 18, 2023 09:08
@Kielek Kielek merged commit 29c1bdd into open-telemetry:main Oct 18, 2023
28 checks passed
@lachmatt lachmatt deleted the ilogger-integration-fix branch October 18, 2023 09:50
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.

Exported logs duplication for some ASP.NET core web apps on net6
4 participants