Skip to content

Commit f15905a

Browse files
authored
Don't log a warning for CORPROF_E_PROFILER_CANCEL_ACTIVATION (#6550)
## Summary of changes Don't log a warning if the classfactory of the tracer or the profiler returns CORPROF_E_PROFILER_CANCEL_ACTIVATION. ## Reason for change The tracer and the profiler return this error code when explicitly disabled (either by an `DD_{0}_ENABLED` setting, or by process exclusion). This is expected and therefore should be logged as info rather than warning. ## Implementation details Just check the HResult. As a bonus, removed a superfluous log. ## Test coverage Tested on my machine.
1 parent 9514e2c commit f15905a

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

shared/src/Datadog.Trace.ClrProfiler.Native/cor_profiler_class_factory.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ HRESULT STDMETHODCALLTYPE CorProfilerClassFactory::QueryInterface(REFIID riid, v
2929
this->AddRef();
3030

3131
// We try to load the class factory of all target cor profilers.
32-
if (FAILED(m_dispatcher->LoadClassFactory(riid)))
33-
{
34-
Log::Warn("Error loading all cor profiler class factories.");
35-
}
36-
32+
// Errors are already logged in the dispatcher.
33+
m_dispatcher->LoadClassFactory(riid);
3734
return S_OK;
3835
}
3936

shared/src/Datadog.Trace.ClrProfiler.Native/dynamic_dispatcher.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,15 @@ namespace datadog::shared::nativeloader
164164
HRESULT result = m_continuousProfilerInstance->LoadClassFactory(riid);
165165
if (FAILED(result))
166166
{
167-
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load continuous profiler class factory in: ",
168-
m_continuousProfilerInstance->GetFilePath());
167+
if (result == CORPROF_E_PROFILER_CANCEL_ACTIVATION)
168+
{
169+
Log::Info("The continuous profiler is disabled");
170+
}
171+
else
172+
{
173+
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load continuous profiler class factory in: ",
174+
m_continuousProfilerInstance->GetFilePath());
175+
}
169176

170177
// If we cannot load the class factory we release the instance.
171178
m_continuousProfilerInstance.release();
@@ -178,7 +185,14 @@ namespace datadog::shared::nativeloader
178185
HRESULT result = m_tracerInstance->LoadClassFactory(riid);
179186
if (FAILED(result))
180187
{
181-
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load tracer class factory in: ", m_tracerInstance->GetFilePath());
188+
if (result == CORPROF_E_PROFILER_CANCEL_ACTIVATION)
189+
{
190+
Log::Info("The tracer is disabled");
191+
}
192+
else
193+
{
194+
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load tracer class factory in: ", m_tracerInstance->GetFilePath());
195+
}
182196

183197
// If we cannot load the class factory we release the instance.
184198
m_tracerInstance.release();
@@ -211,7 +225,7 @@ namespace datadog::shared::nativeloader
211225
HRESULT result = m_continuousProfilerInstance->LoadInstance(pUnkOuter, riid);
212226
if (FAILED(result))
213227
{
214-
Log::Warn("DynamicDispatcherImpl::LoadInstance: Error trying to load the continuous profiler instance in: ",
228+
Log::Warn("DynamicDispatcherImpl::LoadInstance: Error trying to load the continuous profiler instance in: ",
215229
m_continuousProfilerInstance->GetFilePath());
216230

217231
// If we cannot load the class factory we release the instance.

shared/src/Datadog.Trace.ClrProfiler.Native/dynamic_instance.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ namespace datadog::shared::nativeloader
5858
}
5959
else
6060
{
61-
Log::Warn("DynamicInstanceImpl::LoadClassFactory: Error getting IClassFactory from: ", m_mainLibrary.GetFilePath());
61+
if (res == CORPROF_E_PROFILER_CANCEL_ACTIVATION)
62+
{
63+
Log::Info("DynamicInstanceImpl::LoadClassFactory: The IClassFactory from ", m_mainLibrary.GetFilePath(), " is disabled");
64+
}
65+
else
66+
{
67+
Log::Warn("DynamicInstanceImpl::LoadClassFactory: Error getting IClassFactory from: ", m_mainLibrary.GetFilePath());
68+
}
6269
}
6370

6471
Log::Debug("DynamicInstanceImpl::LoadClassFactory: ", res);

0 commit comments

Comments
 (0)