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

Exported logs duplication for some ASP.NET core web apps on net6 #2994

Closed
lachmatt opened this issue Oct 9, 2023 · 3 comments · Fixed by #3003
Closed

Exported logs duplication for some ASP.NET core web apps on net6 #2994

lachmatt opened this issue Oct 9, 2023 · 3 comments · Fixed by #3003
Assignees
Milestone

Comments

@lachmatt
Copy link
Contributor

lachmatt commented Oct 9, 2023

Bug Report

Symptom

Describe the bug
Logs are exported multiple times from application created with minimal api template (e.g dotnet new web).

Expected behavior
Logs should be exported once.

Runtime environment (please complete the following information):

  • OpenTelemetry Automatic Instrumentation version: v1.0.2
  • OS: win10
  • .NET version: net6.0

Additional context
Issue seems to be connected with recent change: #2975
No issues when v1.0.1 of autoinstrumentation is used.
No issue with v1.0.2 on net7.0.
No issue with v1.0.2 on net6.0 for existing web app used for testing logs export.

Reproduce

See sample application and test on fork.

PTAL @rajkumar-rangaraj

@lachmatt lachmatt changed the title Exported logs duplication Exported logs duplication for some ASP.NET core web apps on .net6 Oct 9, 2023
@rajkumar-rangaraj
Copy link
Contributor

@lachmatt I couldn't recreate the issue. I've attached the output from my console and listed the environmental variables I used below.

        "ASPNETCORE_ENVIRONMENT": "Development",
        "CORECLR_ENABLE_PROFILING": "1",
        "CORECLR_PROFILER": "{918728DD-259F-4A6A-AC2B-B85E1B658318}",
        "CORECLR_PROFILER_PATH": "$(SolutionDir)bin\\tracer-home\\win-x64\\OpenTelemetry.AutoInstrumentation.Native.dll",
        "DOTNET_ADDITIONAL_DEPS": "$(SolutionDir)bin\\tracer-home\\AdditionalDeps",
        "DOTNET_SHARED_STORE": "$(SolutionDir)bin\\tracer-home\\store",
        "DOTNET_STARTUP_HOOKS": "$(SolutionDir)bin\\tracer-home\\net\\OpenTelemetry.AutoInstrumentation.StartupHook.dll",
        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper",
        "OTEL_DOTNET_AUTO_HOME": "$(SolutionDir)bin\\tracer-home",
        "OTEL_DOTNET_AUTO_LOGS_CONSOLE_EXPORTER_ENABLED": "true",
        "OTEL_SERVICE_NAME": "CLRProfiler.Self-hosted",
        "OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES": "Examples.*"

output.txt

@lachmatt
Copy link
Contributor Author

@rajkumar-rangaraj
Did you run TestApplication.MinimalApi from fork with target framework set to net6?
I consistently get logs exported multiple times in such scenario.
There are also failures for the new test on CI on my fork.

@lachmatt lachmatt changed the title Exported logs duplication for some ASP.NET core web apps on .net6 Exported logs duplication for some ASP.NET core web apps on net6 Oct 10, 2023
@rajkumar-rangaraj
Copy link
Contributor

rajkumar-rangaraj commented Oct 10, 2023

Thank you, @lachmatt. I was able to reproduce the issue using your fork. The issue arises only when the CLR profiler is enabled on .NET 6.0. Interestingly, the issue doesn't manifest when only the ASPNETCORE_HOSTINGSTARTUPASSEMBLIES is set.

Upon a bit of debugging, I noticed that two different types of IServiceCollection are created for this app type. However, when only ASPNETCORE_HOSTINGSTARTUPASSEMBLIES is set, only the Microsoft.AspNetCore.WebApplicationServiceCollection type is used.

?builder.Services
{Microsoft.AspNetCore.WebApplicationServiceCollection}
    Count: 8
    HostedServices: Count = 0
    InnerCollection: {Microsoft.Extensions.DependencyInjection.ServiceCollection}
    IsReadOnly: false
    TrackHostedServices: true
    Results View: Expanding the Results View will enumerate the IEnumerable
?builder.Services
{Microsoft.Extensions.DependencyInjection.ServiceCollection}
    Count: 17
    IsReadOnly: false
    Results View: Expanding the Results View will enumerate the IEnumerable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants