Skip to content

Commit 602a928

Browse files
authored
Log an error message when the profiler is loaded multiple times (#6503)
## 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.
1 parent f75778d commit 602a928

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tracer/src/Datadog.Tracer.Native/cor_profiler.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
5151
Logger::EnableDebug(true);
5252
}
5353

54+
auto isRunningInAas = IsAzureAppServices();
55+
56+
if (profiler != nullptr)
57+
{
58+
if (isRunningInAas)
59+
{
60+
Logger::Info("The Tracer Profiler is initialized multiple times. This is expected and currently unavoidable when running in AAS.");
61+
}
62+
else
63+
{
64+
Logger::Error("The Tracer Profiler is initialized multiple times. This may cause unpredictable failures.",
65+
" When running aspnetcore in IIS, make sure to disable managed code in the application pool settings.",
66+
" https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/advanced?view=aspnetcore-9.0#create-the-iis-site");
67+
}
68+
}
69+
5470
CorProfilerBase::Initialize(cor_profiler_info_unknown);
5571

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

160-
if (IsAzureAppServices())
176+
if (isRunningInAas)
161177
{
162178
Logger::Info("Profiler is operating within Azure App Services context.");
163179

0 commit comments

Comments
 (0)