Skip to content

Commit

Permalink
Log an error message when the profiler is loaded multiple times (#6503)
Browse files Browse the repository at this point in the history
## Summary of changes

Log an error message when the profiler is loaded multiple times.

## Reason for change

Despite mentioning it in our documentation, we still regularly have
escalations caused by the usage of .NET Framework and .NET Core in the
same pool. Adding an error log will make diagnostic easier.

We could also entirely bail out when we detect multiple initialization,
but I'm afraid we might break existing customers.

## Implementation details

Using the `profiler` field to find out if the profiler was initialized.
It means we won't detect double-initialization if the first
initialization failed midway through, but I don't think we really care.

## Test coverage

Tested on my machine.
  • Loading branch information
kevingosse authored Jan 7, 2025
1 parent f75778d commit 602a928
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tracer/src/Datadog.Tracer.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
Logger::EnableDebug(true);
}

auto isRunningInAas = IsAzureAppServices();

if (profiler != nullptr)
{
if (isRunningInAas)
{
Logger::Info("The Tracer Profiler is initialized multiple times. This is expected and currently unavoidable when running in AAS.");
}
else
{
Logger::Error("The Tracer Profiler is initialized multiple times. This may cause unpredictable failures.",
" When running aspnetcore in IIS, make sure to disable managed code in the application pool settings.",
" https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/advanced?view=aspnetcore-9.0#create-the-iis-site");
}
}

CorProfilerBase::Initialize(cor_profiler_info_unknown);

// we used to bail-out if tracing was disabled, but we now allow the tracer to be loaded
Expand Down Expand Up @@ -157,7 +173,7 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
}
}

if (IsAzureAppServices())
if (isRunningInAas)
{
Logger::Info("Profiler is operating within Azure App Services context.");

Expand Down

0 comments on commit 602a928

Please sign in to comment.